pip editable install fails with pyproject.toml, even with no setup.py import error
Explanation of the problem
The issue reported is related to a project that contains both a setup.py
file and a pyproject.toml
file. When attempting to perform an editable install using the command pip install -e .
, an error occurs. The error message indicates a module not found error for setuptools
. The user mentions that the error is not caused by running the setup.py
file directly but rather by the custom pip
command subprocess used during the build isolation process. The user expresses confusion about this behavior and considers it a regression, suggesting that when running in editable mode with a combination of setup.py
and pyproject.toml
, the build isolation should not be applied to subsequently run the setup.py
file.
The user acknowledges that using the -e
option is not supported by PEP 518 and is considered legacy behavior. However, they believe that the observed error is a regression and propose a more consistent approach that aligns with the legacy behavior. The user highlights that deleting the pyproject.toml
file temporarily allows the installation to proceed without errors, and they argue that this behavior should be the expected outcome. They provide examples of two projects, ansible/ansible-builder
and ansible/ansible-runner
, where the error can be reproduced by running pip install -e .
. The purpose of having both setup.py
and pyproject.toml
in these projects is to incorporate the latest features while maintaining compatibility, particularly for Red Hat Enterprise Linux (RHEL).
In the final part of the description, the user includes a link to the verbose output of the installation process for the ansible/ansible-builder
project. The output demonstrates the error encountered during the installation, and the user explains that the logs were truncated due to their length. The user suggests that any changes in the project’s structure can be made if it would help resolve the issue. They also mention that the setup.py
file in the projects they provided as examples was generated using the library dephell
, specifically using a template designed to create a compatibility-oriented setup.py
script within projects that primarily utilize the new standard. To reproduce the error, the user recommends running pip install -e .
from the root of the respective projects.
Troubleshooting with the Lightrun Developer Observability Platform
Getting a sense of what’s actually happening inside a live application is a frustrating experience, one that relies mostly on querying and observing whatever logs were written during development.
Lightrun is a Developer Observability Platform, allowing developers to add telemetry to live applications in real-time, on-demand, and right from the IDE.
- Instantly add logs to, set metrics in, and take snapshots of live applications
- Insights delivered straight to your IDE or CLI
- Works where you do: dev, QA, staging, CI/CD, and production
Start for free today
Problem solution for pip editable install fails with pyproject.toml, even with no setup.py import error
The issue discussed revolves around the need to have setuptools
installed before using setup.py
and setup.cfg
during the build process. To address this, it is necessary to specify setuptools
as a requirement in the build-system
table of the pyproject.toml
file. A patch provided for the ansible/ansible-builder
project demonstrates how to fix the problem by including setuptools
in the requires
field of the build-system
table. This ensures that setuptools
is available before reading setup.py
.
In response to the problem, a user named Ellen Marie Dash shared a patch that can be applied to resolve the issue. The patch modifies the pyproject.toml
file and specifies setuptools
as a requirement alongside poetry
in the requires
field of the build-system
table. By making this change, the build process will have access to setuptools
before attempting to read the setup.py
file. This solution has been proposed for the ansible/ansible-builder
project and has been shared as a patch.
Additionally, the user named AlanCoding has submitted pull requests to fix the problem in both the ansible/ansible-builder
and ansible/ansible-runner
projects. The pull requests address the issue by incorporating the necessary changes to ensure that setuptools
is included as a requirement during the build process. The provided links lead to the respective pull requests, where the changes can be reviewed and potentially merged to resolve the problem.
Other popular problems with pypa pip
Problem: Inconsistent behavior with respect to dependencies
One of the most commonly encountered problems with pypa pip
is inconsistent behavior with respect to dependencies. The dependencies for a package may be specified in the setup.py
file, but pip
may not always install the correct version or may install additional dependencies that are not specified.
Solution:
The solution to this problem is to use a requirements.txt
file, which specifies the exact versions of all dependencies that should be installed. This file can be provided to pip
with the -r
or --requirements
option to ensure that the correct dependencies are installed.
Problem: Incompatibility with virtual environments
pypa pip
can sometimes have issues when used in virtual environments, such as not recognizing the virtual environment’s Python installation or not installing packages into the virtual environment.
Solution:
The solution to this problem is to use the --user
option when installing packages with pip
. This option causes pip
to install the package in the user’s home directory, which is separate from the virtual environment and will not cause any compatibility issues.
Problem: Unresolved dependencies
Another common problem with pypa pip
is unresolved dependencies, where a package fails to install because one or more of its dependencies cannot be found or installed.
Solution:
The solution to this problem is to use the --no-deps
or --no-dependencies
option when installing packages with pip
. This option causes pip
to only install the requested package and not its dependencies, allowing the user to manually resolve any dependency issues. Alternatively, the pip
community maintains a list of “known good” package indexes that can be used to resolve dependencies, which can be specified with the -i
or --index-url
option.
A brief introduction to pypa pip
pypa pip
is a package manager for Python that allows users to easily install and manage packages for their Python applications. It is designed to work with the Python Package Index (PyPI), a repository of over 200,000 packages that can be installed with pip
. pip
provides a simple command line interface for installing packages and managing dependencies, making it an essential tool for Python developers.
pip
uses the information specified in a package’s setup.py
file to install the package and its dependencies. The setup.py
file contains information about the package such as its name, version, and dependencies, as well as any scripts or data files that should be installed with the package. pip
also supports the use of requirements.txt
files, which specify the exact versions of dependencies that should be installed. This allows developers to have precise control over the packages and versions that are used in their projects.
Most popular use cases for pypa pip
- Installing and managing packages from the Python Package Index (PyPI)
pypa pip
can be used to install packages from PyPI, which is a repository of over 200,000 packages for Python. The pip install
command is used to install packages from PyPI, for example:
pip install <package-name>
- Managing dependencies for Python projects
pypa pip
provides a convenient way to manage the dependencies for Python projects. Packages can specify their dependencies in their setup.py
file, and pip
will automatically install those dependencies when the package is installed. This makes it easy to ensure that all dependencies are correctly installed and up-to-date.
- Creating and distributing Python packages
pypa pip
can also be used to create and distribute Python packages. Developers can use the pip wheel
command to create a wheel (a pre-compiled package) that can be easily installed with pip
. This makes it easy to distribute packages, as users only need to run pip install
to get the latest version of the package and its dependencies.
It’s Really not that Complicated.
You can actually understand what’s going on inside your live applications. It’s a registration form away.