Related: Minimal setup.py
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 (
setuptools.setup(setup_requires=['numpy']) is not recommended):
[build-system] requires = ["setuptools", "wheel","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
python -m pip install yourprogramthis uses
pyproject.tomlalone to install.
Users can also install from local or remote Git repos:
flit installfrom https://github.com/username/yourprogram/archive/master.zipthis downloads and installs the latest Git commit to
masterbranch (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
- ensure your
__init__.pystarts with a one-line description and version. You must increment this version for each PyPi upload (or use
"""My program is 2x faster and 1/3 the size of Hello World.""" __version__ = '0.1.0'
pyproject.tomlcontains something like:
[build-system] requires = ["flit"] build-backend = "flit.buildapi" [tool.flit.metadata] module = "myprogram" author = "Author Name" author-email = "[email protected]" home-page = "https://github.com/username/reponame" requires=['numpy','matplotlib (>=2.1)'] requires-python='>=3.5' description-file='README.rst' classifiers=[ 'Development Status :: 4 - Beta', 'Programming Language :: Python']
- Sign up for PyPi account. It may take several hours to get the confirmation email.
~/.pypircwith the content
[pypi] username=<your pypi username>
Note that I did NOT save my 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
python -m pip install myprogram
python -m pip install flit
- These old methods are superceded by the methods above.
python setup.py install
python -m pip install .→
python setup.py develop
python -m pip install -e .→
flit install -s
python setup.py sdist bdist_wheel upload→
- flit reference
To my knowledge,
python -m pip install -e .
- Python-only project should use