本文用实例演示如何把自己的python代码库打包上传pypi,以使用pip进行安装。
打包发布
[yanjingang pydp]$ pip install setuptools wheel twine #安装打包和上传工具 [yanjingang pydp]$ vim setup.py #打包配置 #!/usr/bin/env python # -*- coding: utf-8 -*- ''' 打包 依赖:pip install setuptools wheel twine Cmd: 打包: python setup.py bdist_wheel (.whl包) #python setup.py sdist --formats=gztar (.tar.gz包) 本地安装测试: python setup.py develop (源码软链安装) #python setup.py install (源码正式安装) #pip install dist/pydp-0.0.23-py3-none-any.whl (使用.whl包安装) 上传pypi: twine upload dist/pydp-0.0.23-py3-none-any.whl twine upload dist/pydp-0.0.23-py2-none-any.whl pypi安装: pip search pydp pip install pydp --upgrade ''' from setuptools import setup, find_packages #说明文档 long_description = "" with open("USAGE.md", "r") as f: long_description = f.read() setup( name="pydp", version="0.0.23", description="Data Processing Lib", author_email="yanjingang@mail.com", packages=find_packages("./"), include_package_data=True, # 按./MANIFEST.in配置导入非.py文件 long_description=long_description, long_description_content_type="text/markdown", url="http://www.yanjingang.com/docs/pydp/dp.html", install_requires=[ 'numpy', 'opencv-python', 'pillow', 'pyquery', 'xpinyin', 'pyyaml', 'jieba', 'pydub', 'librosa', 'PyMySQL', 'face_recognition', 'baidu-aip', ] ) [yanjingang pydp]$ vim MANIFEST.in #导入非.py文件配置 recursive-include dp/data *.dict *.wav *.png *.jpg #递归导入dp/data目录下的所有特定后缀文件 prune dp/data/tmp #排除dp/data/tmp目录 [yanjingang pydp]$ python setup.py bdist_wheel #打包 [yanjingang pydp]$ twine upload dist/pydp-0.0.23-py3-none-any.whl #上传pypi [yanjingang pydp]$ pip install pydp --upgrade #pip安装 [yanjingang pydp]$ python #import >>> from dp.resnet import resnet_cifar100 >>> from dp import utils, audio, tts, asr, face, da >>> utils.md5('abc') '900150983cd24fb0d6963f7d28e17f72'
Pypi项目地址:https://pypi.org/project/pydp/ 对外公开的项目,再补充下详细的说明文档即可。
*需要注意打包环境的python -V,py3的包只能用于python3.x(另外pypi分发的cdn貌似有点延迟,刚upload后如果遇到能seach到但install又提示找不到的情况时等一等再试就好了)
生成文档
生成文档
0.安装sphinx和皮肤
pip install Sphinx sphinx_rtd_theme
1.创建doc目录
mkidr doc
cd doc
2.生成并修改配置文件
sphinx-quickstart
vim conf.py
import os
import sys
import sphinx_rtd_theme
sys.path.insert(0, os.path.abspath('../dp/'))
#html_theme = 'alabaster'
html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
3.生成指定代码目录的.rst文件
sphinx-apidoc -o . ../dp/
4.生成html格式的文档
make html
5.访问文档
doc/_build/html/dp.html
http://www.yanjingang.com/docs/pydp/dp.html
yan 19.3.22
参考:https://blog.csdn.net/chenfeidi1/article/details/80873979#%E5%88%86%E5%8F%91%E5%B7%A5%E5%85%B7-setuptools
https://www.cnblogs.com/niejinmei/p/8918858.html