question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Build isolation doesn't work with Python installation that requires PYTHONPATH for stdlib

See original GitHub issue

Environment

  • pip version: 19.2.3
  • Python version: 2.7 / 3.7
  • OS: Windows (will probably fail on nix as well?)

Custom env, with PYTHONPATH, PYTHONHOME set.

Description When installing PEP518/517 package based on setuptools, the install fails with an ImportError: No module named site on py 2.7, or ModuleNotFoundError: No module named 'encodings' on py3.7.

Expected behavior Install completes successfully.

How to Reproduce Repro on Windows:

  1. Take a normal/fresh CPython install with pip installed in e.g. C:\testpython, put it in PATH (without any other py installs) (SET PATH=C:\testpython).
  2. SET PYTHONHOME=C:\testpython (to ensure no other system python is picked up via registry).
  3. Move C:\testpython\Lib to C:\testpython\hidden\Lib.
  4. See that calling python fails with the above error.
  5. SET PYTHONPATH=C:\testpython\hidden\Lib;C:\testpython\hidden\Lib\site-packages.
  6. See that python now works again
  7. Upgrade pip if needed with python -m pip install --upgrade pip --target=C:\testpython\hidden\Lib\site-packages
  8. Do a source install of a a package with pyproject.toml that uses setuptools under the hood. python -m pip install path_to_src_package --target=C:\testpython\hidden\Lib\site-packages. It fails since pip internally overwrites PYTHONPATH for the build env, so its subprocess call to sys.executable fails. This is where it overwrites PYTHONPATH:

https://github.com/pypa/pip/blob/53ee380d95b49a66c87eea6bda41b1c1fef7c600/src/pip/_internal/build_env.py#L123-L127

Output

C:\testpython>python -m pip install path_to_src_package
Processing path_to_src_package
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  ERROR: Command errored out with exit status 3221226505:
   command: 'C:\pytest\python.exe' 'C:\testpython\hidden\Lib\site-packages\pip\_vendor\pep517\_in_process.py' get_requires_for_build_wheel 'C:\Users\username\AppData\Local\Temp\tmpr4n0ozpb'
       cwd: C:\Users\username\AppData\Local\Temp\pip-req-build-o60yaw8r
  Complete output (4 lines):
  Fatal Python error: initfsencoding: unable to load the file system codec
  ModuleNotFoundError: No module named 'encodings'

  Current thread 0x000027b8 (most recent call first):
  ----------------------------------------
ERROR: Command errored out with exit status 3221226505: 'C:\testpython\python.exe' 'C:\testpython\hidden\Lib\site-packages\pip\_vendor\pep517\_in_process.py' get_requires_for_build_wheel 'C:\Users\username\AppData\Local\Temp\tmpr4n0ozpb' Check the logs for full command output.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
vidartfcommented, Oct 15, 2019

All I’d ask is that if at any point, you hit any pip issues, you demonstrate that they happen in a vanilla environment before asking for help here. (Or at a minimum, you make it clear that you’ve got a weird setup and link back here in the issue report).

Of course. I was hoping the OP was proof of me understanding what a proper MWE is 😉

0reactions
pradyunsgcommented, Feb 5, 2020

Thanks @vidartf for a basically excellent bug report; and for being understanding on why we view this as a wont-fix.

I’ll go ahead and close this now. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

PYTHONPATH priority after standard library? - Ideas
The Interpreter independent isolated/virtual environments thread a while ago raised a similar need (virtual environment site-packages directory ...
Read more >
No module named 'encodings' while running python in iOS
I just got this working after days of trying! Using Python 3.11. For anyone wondering, we're using a version of Python patched for...
Read more >
Release 0.24.0-pre Gregory Szorc
Building oxidized_importer from source requires a working Rust ... of the Python standard library and needed to be explicitly installed.
Read more >
Python and the Module Search Path | by Mark Jamison
That's all great for importing the python standard library of default ... as we don't really care too much about things like $PYTHONPATH...
Read more >
How to Manage Python Dependencies in PySpark
If they do not have required dependencies installed in all other ... Virtualenv is a Python tool to create isolated Python environments.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found