Python如何將模塊打包并發布
想要把自己開發的庫分享給別人使用, 使用 pip install 命令來安裝 , 需要學習如何制作一個python 安裝包
一、注冊pypi賬號
https://pypi.org/account/register/
二、創建setup.py和pypirc文件
setup.py模板(該文件放在項目根目錄下)
from os.path import abspath, dirname, join from setuptools import setup, find_packages # 獲取requirements.txt里的依賴信息 install_reqs = [req.strip() for req in open(abspath(join(dirname(__file__), ’requirements.txt’)))] with open('README.md', ’r’, encoding='utf-8') as f: long_description = f.read() setup( name=’模塊名’, version=’0.0.1’, packages=find_packages(), url=’網址’, license=’協議’, author=’作者姓名’, author_email=’作者郵箱’, description=’描述信息’, long_description=long_description, long_description_content_type='text/markdown', install_requires=install_reqs, )
pypirc模板 (該文件放在家目錄內)
這個文件用來存儲剛才注冊pypi賬號信息
[distutils] index-servers=pypi [pypi] repository = https://upload.pypi.org/legacy/ username = 剛才注冊的用戶名 password = 剛才注冊的密碼
三、安裝依賴
pip install --upgrade pip twine wheel setuptools
四、打包
python setup.py sdist bdist_wheel
打包之后 會在項目的dist目錄內生成whl文件
五、將whl文件上傳到pypi服務器
twine upload dist/*
以上就是Python如何將模塊打包并發布的詳細內容,更多關于python 模塊打包發布的資料請關注好吧啦網其它相關文章!
相關文章:
