-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Isolated build fails with generic StopIteration
when pip is not provisioned in venv
#266
Comments
Transferred to the build tracker for greater visibility. |
This could have one of a number of causes:
|
Looked into this a bit more and found that after
Notice how |
Looks like CentOS patches the You can install |
I don’t think there’s a good way to add hard dependencies based on Linux distribution variants. I think this is less about patching venv, but that on most Linux distributions, pip is a separate package from the base Python installation, and ensurepip does not work without the user installing pip from the system package first. There has been long-running tension between Linux distribution maintainers and Python packaging tools; distributions really don’t want to put pip into the base Python package (for valid reasons), but most Python packaging tools want to be able to boostrap pip (also for valid reasons). I think the best |
Should ensurepip not error then if it can't install pip if pip is not installed system-wide? I was under the impression that it did on Debian. |
That depends on how CentOS packages and patches things. IIRC Debian just outright removed ensurepip without noticing it’s used by venv, which (fortunately in a sense?) made the error very visible. |
I see this happening when running build under tox. The underlying Python is a clean installation from sources, not a distro-provided bastardization. Requiring |
I just hit this issue as well. I'm a developer for the Spack package manager. Spack installs each package into a separate installation prefix, so we rely on things like P.S. If P.P.S. This wouldn't be an issue if build vendored its dependencies like pip/setuptools/flit/poetry/etc. |
pip is not a dependency, we use the standard library Please fill a bug report with your distributor if their package for pypa/build does not depend on whatever is needed to make ensurepip usable on that environment. If you are using pypa/build from a virtual environment, you can still fill a bug report with your distributor to ask them to stop this behavior, but they will probably just gonna tell you that the user should be aware that ensurepip only works with certain packages installed (they usually make them optional dependencies) 🤷 |
Spack builds Python with the Unfortunately I don't have a distributor to open an issue with, as I'm the distributor. I'm maintaining Spack and Spack's Python packages, so if it's possible to fix this on our side, I'm probably the one to do it. Can you tell me exactly how ensurepip needs to work for this library? |
I believe If you do not patch the Python installation in any way, this should work OOTB. CPython bundles the pip and setuptools wheels required for ensurepip, https://github.com/python/cpython/tree/main/Lib/ensurepip/_bundled. I'd say that the first step would be checking if they are there. |
Yes, they are there: $ ls lib/python3.8/ensurepip/_bundled/
pip-21.1.1-py3-none-any.whl setuptools-56.0.0-py3-none-any.whl |
Then try to use venv to setup a virtual environment with pip (it does by default) and check if that works. If it does, then you are likely running into other problem, and we will have to debug that. |
Can you give me some venv commands that you expect to work? Never used it before, as Spack has its own virtual environments. |
You can delete |
Looks like the venv doesn't have pip installed. |
StopIteration
when pip is not provisioned in venv
FWIW, removing |
Dug a bit deeper into this thanks to the help of @wdconinc. When you build Python, you have 3 options:
It looks like I'm still unsure why |
Are you manipulating the PYTHONPATH in Spack? |
I assume what's happening is pip does not install itself in the venv because it believes it's already installed. When you pass |
Yes, we are manipulating
Hmm, so I don't have any |
So in the environment that you execute build there's no pip? Are you sure? |
I don't have Spack, but here's a simple repro using Nix, which manipulates the Python path in the same way:
|
Ultimately, this needs to be fixed in Python. If
|
Thanks for the detailed diagnosis @layday. I think you're right, this is not an issue of how Python was built, but whether or not pip is present in I'll see if I can extract a minimal patch from 38099ad and add it to our |
Okay, I had assumed there was some interplay with installing pip with Python, but it makes things a lot easier if there isn't. |
For anyone else who runs into this problem, the following minimal patch solved it for me: --- a/src/build/env.py 2021-09-16 16:20:01.000000000 -0500
+++ b/src/build/env.py 2022-01-23 15:08:26.000000000 -0600
@@ -254,6 +254,7 @@
"""
import venv
+ os.environ.pop('PYTHONPATH', None)
venv.EnvBuilder(with_pip=True, symlinks=_fs_supports_symlink()).create(path)
executable, script_dir, purelib = _find_executable_and_scripts(path)
Hopefully #406 is merged soon. Thanks for your help @layday! |
+1 on this. I am a Spack user and would like this to work :) Interestingly in one of my spack environments |
@adamjstewart It looks like if you have python 3.9 in your spack env it works, but if you use 3.8 you get the OPs error. I tried specifically 3.9.9 and 3.8.12 btw. |
@salotz-sitx does spack/spack#28562 solve your issue? For me, it didn't matter which Python version I was using, it mattered if |
I didn't try spack/spack#28562.
and pip is in the first in the list: |
I've run into this issue in jaraco/jaraco.packaging#8. After switching from pep517 to build for loading metadata from an unbuilt project, now all docs builds are failing in RTD. I don't know if RTD is using Spack or Nix or maybe just something with PYTHONPATH. Is the recommended workaround to include |
https://build.opensuse.org/request/show/1032671 by user mcalabkova + dimstar_suse - Update to v9.1.1 * Change requirement to build[virtualenv] as workaround for pypa/build#266. - Update to v9.1.0 * Prefer build to pep517 for loading package metadata.
Thank you for providing feedback on Python packaging!
To help us help you, please fill out as much of the following as you can. If a question is not relevant, feel free to skip it.
CentOS 7.6.1810
Python 3.6.5
pip-21.0.1
https://packaging.python.org/tutorials/packaging-projects/
Created a sample-project according to the tutorial.
Set up a virtual environment, upgraded pip to the latest and installed build-0.3.1.post1
Ran
python -m build --sdist --wheel
to create both a wheel and an sdist, and then encountered this:It looks like build did not add pip to the /tmp/build-env-*/ site-packages.
The text was updated successfully, but these errors were encountered: