Following the simple tutorial at: https://www.freecodecamp.org/news/how-to-create-and-upload-your-first-python-package-to-pypi/
We use setuptools as a "build system" here. This is declared in pyproject.toml.
Note that you can safely move all configuration settings in setup.cfg to pyproject.toml if you
decide to change the build system to flit or poetry, for example.
NOTE: You cannot use as follows unless you build the package. See further instructions.
E.g.
from multiply import multiply_by_three
from divide import divide_by_three
multiply_by_three.multiply_by_three(9)
divide_by_three.divide_by_three(21)
In the same directory as the pyproject.toml file, do
python -m pip install --upgrade build
python -m build
Once the process above is completed, a new directory is generated called dist/ with two files in it. The .tag.tz file is the source archive and the .whl* file is the built archive. These files represent the distribution archives of our Python package which will be uploaded to the Python Package Index and installed by pip in the following sections.
We'll upload the package to PyPI. If we're just testing things out initially, we can upload to TestPyPI instead. Then upload to PyPI after.
Make an account at https://test.pypi.org/
After making an API token, we need to upload our distribution archives. To do so, we have to use an upload tool to upload our package. The official PyPI upload tool is twine, so let's install twine and upload our distribution archives under the dist/ directory.
python -m pip install --upgrade twine
python -m twine upload --repository testpypi dist/*
After using python -m build to create a dist/ directory, do
python -m pip install --upgrade twine
twine upload dist/*
Then install your package with pip like:
# If using actual PyPI:
python -m pip install basicpkg-tutorial-drew
# If using Test PyPI:
python -m pip install --index-url https://test.pypi.org/simple/ --no-deps basicpkg-tutorial-drew
After this, you can use the package!
If you wanna change the setup configuration, dependencies, etc, make sure to delete dist/ and src/basicpkg*
first. Then repeat the
python -m build
twine upload dist/*
process.