1. 程式人生 > >自定義package上傳到 pypi

自定義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

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

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