pip ≥ 10 can use
pyproject.toml instead of (or more commonly, along with)
setup.py, for simpler syntax.
pyproject.toml is particularly useful for
programs where Numpy must be installed before running
pyproject.toml for simpler PyPI uploads, and can also install programs (as alternative to
pip), even without
End users can simply
flit installfrom Github, without needing to
git clone or use PyPI (unless they want to).
pyproject.toml lower Python program distribution difficulty for developers who don’t want to mess with PyPI, but also make it easier for those who do use PyPI.
This example uses
pyproject.toml to augment
setup.py by first installing Numpy.
setup_requires in setup.cfg or setup.py is not recommended as it will cause offline (not internect-connected) systems to error on installing the Python package.
[build-system] requires = ["setuptools", "numpy"]
setup.py is constructed as usual, and when doing
pip install -e . or
pip install mypkg, Numpy will be installed first so that f2py or other Numpy-based extension modules can be built.
A real-life example of this is in
Example: pyproject.toml instead of setup.py
flit publishto PyPI
pip install yourprogramthis uses
pyproject.tomlalone to install.
Users can also install from local or remote Git repos:
flit installfrom https://github.invalid/username/yourprogram/archive/main.zipthis downloads and installs the latest Git commit to
mainbranch (or other branch or release version they choose)
git cloneyour repo and install in develop mode by
flit install -s. This puts a symbolic link to your local Git directory (where you
This standard was defined in
Assuming your package is named
myprogram, have a directory structure like
pyproject.toml myprogram/ __init__.py
__init__.py starts with a one-line description and version.
You must increment this version for each PyPI upload (or use
"""Module docstring text""" __version__ = '0.1.0'
pyproject.toml contains something like:
[build-system] requires = ["flit"] build-backend = "flit.buildapi" [tool.flit.metadata] module = "myprogram" author = "Author Name" author-email = "email@example.com" home-page = "https://github.com/username/reponame" requires=['numpy', 'matplotlib (>=2.1)'] requires-python='>=3.6' description-file='README.md' classifiers=[ 'Development Status :: 4 - Beta', 'Programming Language :: Python']
Sign up for PyPI account. It may take several hours to get the confirmation email.
~/.pypirc with the content
Do NOT save password for security.
In your Python package directory that you want to upload
Now your package is live to the world on PyPI. Anyone can install it via
pip install myprogram
pip install flit
These methods are superseded by the methods above.
python setup.py install
pip install .→
python setup.py develop
pip install -e .→
flit install -s
python setup.py sdist bdist_wheel upload→