pythonpipsetuptoolspython-poetrypyproject.toml

How to install a package using pip in editable mode with pyproject.toml?


When a project is specified only via pyproject.toml (i.e. no setup.{py,cfg} files), how can it be installed in editable mode via pip (i.e. python -m pip install -e .)?

I tried both setuptools and poetry for the build system, but neither worked:

[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

I get the same error for both build systems:

ERROR: Project file:///tmp/demo has a 'pyproject.toml' and its build backend is missing the 'build_editable' hook. Since it does not have a 'setup.py' nor a 'setup.cfg', it cannot be installed in editable mode. Consider using a build backend that supports PEP 660.

I'm using this inside a conda environment, the following is my version of setuptools and pip:

$ conda list | grep setuptools
setuptools                58.3.0                   pypi_0    pypi
$ python -m pip --version
pip 21.3.1

Solution

  • PEP 660 – Editable installs for pyproject.toml based builds defines how to build projects that only use pyproject.toml. Build tools must implement PEP 660 for editable installs to work. You need a front-end (such as pip ≥ 21.3) and a backend. The statuses of some popular backends are:

    Note: To be able to do an editable installation to your user site (pip install -e --user), you need a system installed setuptools v62.0.0 or newer.