Open edmorley opened 1 year ago
Something else I've just discovered - this issue only affects uWSGI when it was installed into the user site-packages using using pip install --user
. If uWSGI was installed into the system site-packages or else into a virtualenv's site-packages, then the error doesn't occur.
Summary
uWSGI calculates the Python stdlib location incorrectly for Python installs that have been relocated, resulting in the server failing to start due to:
This appears to be because uWSGI is using the wrong
sysconfig
APIs to calculate Python home and the location of the standard library - and so uWSGI attempts to use them from the hardcoded compilation time paths, rather than the new Python location reported bysys.prefix
and othersysconfig
APIs.Steps to reproduce
mkdir uwsgi-testcase && cd $_
touch Dockerfile app.py
Dockerfile
andapp.py
to have the contents listed belowdocker build -t uwsgi-test .
docker run --rm -it uwsgi-test
docker run --rm -it uwsgi-test python -c 'import pprint, sys, sysconfig; print("sys.prefix:", sys.prefix); print("sys.path:", pprint.pformat(sys.path)); print("sysconfig.get_paths():", pprint.pformat(sysconfig.get_paths()))'
Expected
Python path configuration
section of the uWSGI server output lists the correct locations for the Python installation (paths under/foo/python
) that match whatsys.prefix
andsysconfig.get_paths()
report.Actual
Python path configuration
section of the uWSGI server output lists the wrong locations for the Python installation (paths under/app/.heroku/python
) that don't match whatsys.prefix
andsysconfig.get_paths()
report.PYTHONHOME
env var has to be set to override uWSGI's incorrect location. For example, by runningdocker run --rm -it --env PYTHONHOME='/foo/python' uwsgi-test
.In comparison, Python's stdlib has the correct paths:
Versions
Notes
sys.prefix
andsysconfig.get_paths()
report the correct locations. How Python determines the Python location is documented here.sysconfig
(egLIBS
andSYSLIBS
) which are hardcoded by Python at time of build, and so don't change when the Python installation is relocated. To resolve this issue, it seems these usages should be switched to one of the othersysconfig
APIs instead. See: