1、首先要有自己的pypi賬號,去官網注冊
2、我的目錄結構,其中build、cbot.egg-info以及dist是打包的時候生成的,並且最外層的叫什么都無所謂。但要確保setup.py和內層的這個是同級的,別把setup.py放到包文件夾里面去了。
3、導出requirements.txt文件(存放使用的依賴)
pip freeze > requirements.txt
4、書寫README.md文件,該文件是可以顯示到官網中的說明的。
我的部分說明:md的書寫語法自行百度
5、新建MANIFEST.in文件,文件名必須是這個。
6、接下來書寫setup.py文件,這個是最重要的

# coding=utf-8 from setuptools import setup, find_packages with open("README.md", "r") as fh: long_description = fh.read() setup( name='cbot', version="0.1.0", description=( 'A chinese chat bot' ), long_description=open('README.md', 'r').read(), long_description_content_type="text/markdown", author='felix', author_email='felix2@foxmail.com', maintainer='felix', maintainer_email='felix2@foxmail.com', license='MIT License', packages=find_packages(), platforms=["ubuntu", 'windows'], url='https://github.com/wangyitao/cbot', classifiers=[ 'Development Status :: 4 - Beta', 'Operating System :: OS Independent', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Programming Language :: Python', 'Programming Language :: Python :: Implementation', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Topic :: Software Development :: Libraries' ], install_requires=[ 'sqlalchemy', 'python-dateutil', 'python-levenshtein', 'requests', ] )
6、打包上傳
打包前可以先檢查一下。
python setup.py check
打包
python3 setup.py sdist build
上傳,使用twine,pip install twine 安裝
twine upload dist/*
上傳成功否就能在自己的pypi賬號中看到了。
但是並不是馬上就能使用pip安裝了。需要等待一段時間。