将python包上传到PyPI
来源:互联网 发布:设置蜂窝移动网络 编辑:程序博客网 时间:2024/04/26 15:23
目标:
将自己写的python包上传到PyPI上,这样其他人就可以用pip下载了
总体文件结构:
--- Root directory (name doesn't matter) |- your_library | |- __init__.py | |- actual_code_goes_here.py |- setup.py |- README.rst |- LICENSE.txt
创建setup.py文件
例子:
from setuptools import setup, find_packagessetup( name="advisorhelper", packages=find_packages(), version='0.9.3', description="command line tool for auto tuner", author="libbyandhelen", author_email='libbyandhelen@163.com', url="https://github.com/username/reponame", download_url='https://github.com/username/reponame/archive/0.1.tar.gz', keywords=['command', 'line', 'tool'], classifiers=[], entry_points={ 'console_scripts': [ 'command1 = advisorhelper.cmdline:execute' 'command2 = adviserserver.create_algorithm:run', 'command3 = adviserserver.run_algorithm:run' ] }, install_requires=[ 'grpcio>=1.7.0', 'numpy', 'requests', ])
注:
- Name: 包的名字
- find_packages(): 默认以setup.py所在路径为源路径(也可以用参数指定),递归遍历找到所有的python包(含有init.py的文件夹),支持include,exclude参数
- find_packages(exclude=[“.tests”, “.tests.“, “tests.“, “tests”])
- version:如修改后再次上传,需要使用不同版本号
- entry_points:指定包的入口
- install_requires: 指定此包的依赖
- url 和 download_url不是必须,可填写github地址
在 PyPI Live 上注册一个账户
https://pypi.python.org/pypi?%3Aaction=register_form
创建.pypirc文件,这样之后每次上传就不用登录了
[distutils]index-servers = pypi pypitest[pypi]repository=https://pypi.python.org/pypiusername=your_usernamepassword=your_password[pypitest]repository=https://testpypi.python.org/pypiusername=your_usernamepassword=your_password
- /home/yourname/.pypirc on Mac and Linux
C:\Users\YourName.pypirc on Windows - 改变文件读写权限,因为其中含有明文的密码
chmod 600 ~/.pypirc on Mac and Linux
Windows中右键->属性->安全
检查一下setup.py的语法是否正确
python setup.py check
将包上传到PyPI Live
python3.5 setup.py sdist upload -r pypi
注意这里用的是python3.5,之前用python3.6会报[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed这个错误,python3.5就可以了,其他版本没有试过
参考资料
http://peterdowns.com/posts/first-time-with-pypi.html
http://setuptools.readthedocs.io/en/latest/setuptools.html#using-find-packages
阅读全文
0 0
- 将python包上传到PyPI
- 将Python包上传到TestPypI
- 怎么快速将war包上传到服务器?
- 如何通过网页方式将jar包上传到nexus
- iOS 如何利用Application Loader 将ipa包上传到AppStore
- 用Application Loader 将ipa包上传到AppStore
- 怎样将jar包上传到Sonatype Nexus仓库
- iOS 如何利用Application Loader 将ipa包上传到AppStore
- 如何通过网页方式将jar包上传到nexus
- 如何通过网页方式将jar包上传到nexus?
- 如何将jar包上传到Maven中央仓库
- 把ipa包上传到AppStore
- 把ipa包上传到AppStore
- 如何将从myeclipse中导出来的war包上传到新浪服务器
- 用eclipse怎样将本地的项目打成jar包上传到mevan仓库
- 用eclipse怎样将本地的项目打成jar包上传到maven仓库
- 将自己写的Python代码打包放到PyPI上
- 将jar包上传到Hadoop服务器并执行jar包的方法--参数不对应导致报错output directory already exists
- 报告:拥抱机器–AI与商业的碰撞
- Strategy Analytics:甄别语音驱动IoT的机遇
- VentureBeat:2018年全球人工智能八大趋势
- 当自动驾驶普及时 驾驶工人能做什么?
- xml DTD(document type definition)
- 将python包上传到PyPI
- 刚刚,李飞飞在谷歌开发者大会宣布谷歌AI中国中心正式成立
- 几秒钟一个方案,正确率93%优品率80%,小库科技如何打响建筑领域「第一炮」?
- 仅需15分钟,使用OpenCV+Keras轻松破解验证码
- 百度AI开发者实战营北京收官,公布首批22家AI加速器成员
- 一文概述2017年深度学习NLP重大进展与趋势
- python 安装pip
- 建造者模式
- libevent evutil_gettime_monotonic_