Python如何將模塊打包并發(fā)布
想要把自己開發(fā)的庫分享給別人使用, 使用 pip install 命令來安裝 , 需要學(xué)習(xí)如何制作一個(gè)python 安裝包
一、注冊(cè)pypi賬號(hào)
https://pypi.org/account/register/
二、創(chuàng)建setup.py和pypirc文件
setup.py模板(該文件放在項(xiàng)目根目錄下)
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=’網(wǎng)址’, license=’協(xié)議’, author=’作者姓名’, author_email=’作者郵箱’, description=’描述信息’, long_description=long_description, long_description_content_type='text/markdown', install_requires=install_reqs, )
pypirc模板 (該文件放在家目錄內(nèi))
這個(gè)文件用來存儲(chǔ)剛才注冊(cè)pypi賬號(hào)信息
[distutils] index-servers=pypi [pypi] repository = https://upload.pypi.org/legacy/ username = 剛才注冊(cè)的用戶名 password = 剛才注冊(cè)的密碼
三、安裝依賴
pip install --upgrade pip twine wheel setuptools
四、打包
python setup.py sdist bdist_wheel
打包之后 會(huì)在項(xiàng)目的dist目錄內(nèi)生成whl文件
五、將whl文件上傳到pypi服務(wù)器
twine upload dist/*
以上就是Python如何將模塊打包并發(fā)布的詳細(xì)內(nèi)容,更多關(guān)于python 模塊打包發(fā)布的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
