Hey me dear readers,
Key contents
- Update local packages for distribution.
- Create a distribution package on your local machine, and check the dist/directory for the new version files
- Upload the distribution files to test-pypi server
- Test the upload with a local installation
- Upload the distribution files to pypi
Suppose:
- You have updated a Python package, for example to add a feature or fix a bug
- You have an up-to-date local repository and have pushed all changes to GitHub.
- You have incremented the version number for the package
- You have accounts on
pypi
andtest.pypi
You will need to have in your repository:
- a suitably-configured setup.py file
- a README.md file (this will be your
pypi
documentation page) - a License file (may find this on MIT blog for pypi license)
- If these are not present, add them now
: Update local packages for distribution
python -m pip install --user --upgrade setuptools wheel
python -m pip install --user --upgrade twine
2: Create distribution packages on your local machine, and check the directory for the new version of files
python setup.py sdist bdist_wheel
ls dist
3: Upload the distribution files to pypi
’s test server
python -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*
Check the upload on the test.pypi server:
4: Test the upload with a local installation
Create a new test environment
conda create --name test_pypi python=3.8
- Install your package from the test server
python -m pip install --index-url https://test.pypi.org/simple/ --no-deps <PACKAGE>Start Python, import the package, and test the version
5: Upload the distribution files to pypi
python -m twine upload dist/*
Check the upload at pypi