Build isolation doesn't work with Python installation that requires PYTHONPATH for stdlib
See original GitHub issueEnvironment
- 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:
- 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
). SET PYTHONHOME=C:\testpython
(to ensure no other system python is picked up via registry).- Move
C:\testpython\Lib
toC:\testpython\hidden\Lib
. - See that calling
python
fails with the above error. SET PYTHONPATH=C:\testpython\hidden\Lib;C:\testpython\hidden\Lib\site-packages
.- See that
python
now works again - Upgrade pip if needed with
python -m pip install --upgrade pip --target=C:\testpython\hidden\Lib\site-packages
- 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 sincepip
internally overwritesPYTHONPATH
for the build env, so its subprocess call tosys.executable
fails. This is where it overwritesPYTHONPATH
:
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:
- Created 4 years ago
- Comments:9 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Of course. I was hoping the OP was proof of me understanding what a proper MWE is 😉
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. 😃