自定义package上传到 pypi

How to upload package to pypi

Install twine

pip install twine

Init file

First of all, make sure that the structure of project is correct. Says, your project code in a folder call ‘foo’, then you have README and some other files in the same level.

For example,

.
├── foo
│ └── a.py
└── readme.md
Secondly, add specify file to the root folder.

  • README.rst
  • MANIFEST.in
  • setup.py
  • setup.cfg(option)
    pypi do not know markdown format readme, there is only rst format available!!!
    由于pypi不能使用markdown格式的readme,因此需要用rst格式,rst语法有共通之处,详见这篇博文

setup.py

look at
https://github.com/pypa/sampleproject/blob/master/setup.py

after finish setup.py
you can use

pip install -e .
install package locally on editable mode.
It will also install dependency.

Make dist

1 Build source distribution

run:
python setup.py sdist

2 Build wheel.

If your code compat py2 and py3:
python setup.py bdist_wheel --universal

else:
python setup.py bdist_wheel

if your code is specify for some python version, add python tag in setup.cfg

For example, if your code is only available in py3.5 and 3.4

[bdist_wheel]
python-tag = py35, py34

Upload

look at http://python-packaging-user-guide.readthedocs.io/en/latest/distributing/#uploading-your-project-to-pypi

Create a account on pypi, register your package, write a ~/.pypirc
[distutils]
index-servers=pypi

[pypi]
repository = https://pypi.python.org/pypi
username = <username>
password = <password>

left the password empty, you can use twine with -p PASSWORD

upload your dist folder

twine upload dist/*

Reference

http://python-packaging-user-guide.readthedocs.io/en/latest/distributing/
http://peterdowns.com/posts/first-time-with-pypi.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值