-
Notifications
You must be signed in to change notification settings - Fork 66
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
Embedded Python interpreter on macOS puts system site-packages
path before venv paths
#628
Comments
To work around this, you can specify Ive tested this on |
As for a long term solution, it is possible to programmatically specify |
Update, this doesn't seem to be a TL;DR Run PYTHONEXECUTABLE=$(which python) ngen <args>
|
In testing #626, it was discovered that on macOS, when a venv is active, the interpreter embedded in ngen reports
sys.path
directories including a system-levelsite-packages
path like*/Frameworks/Python.framework/Versions/3.*/lib/python3.*/site-packages
of the same version as the venv... this does not occur (or has not been observed) on Linux.Initially it was thought that this might be a result of #540 (or possibly #592), but checking out the commit before #540 (c261af4) shows the same behavior. This can cause several problems, and it was observed that if there is a mismatched NumPy version in the system path from the on in a venv that this would trigger the mismatch exception added in #558.
Other (worse) things could happen because of this, for example if different BMI module versions were installed in a venv vs. the system/Python.framework site-packages paths, then an unexpected version could be transparently used (this could be one source of the problems described in #441). Generally installing things in the system Python path (or user site) is likely to cause problems like this, but is not uncommon--especially NumPy seems to end up there frequently, given search results.
It seems as if this may be different behavior of pybind11 (or the embedded interpreter tooling of CPython, which is used by pybind11?) on macOS, but the cause is largely unknown. Some interesting info on pybind11's embedding settings that may be relevant (or not).
Current behavior
ngen built on macOS will include a path like the 4th line in the paths returned from
sys.path
in the embedded pybind11 Python interpreter:...While in the same environment,
python
itself reports different paths:Notably, ngen explicitly adds the venv paths in InterpreterUtil.hpp ... but it does not add the system site-packages path, and its origin is unknown.
Expected behavior
The system site-packages path for the venv python version should not be included. This is an example from a Linux (RHEL7) system:
(note that the python2.7 site-packages directories are also not desirable but don't seem to cause the same problems)
Steps to replicate behavior (include URLs)
ngen
without any command line arguments and inspect the Python system pathspython -c 'import sys; print("\n".join(sys.path))'
Or...
python3 -m pip install numpy==1.24.3
python -m pip install numpy>1.24
.ngen
with the venv active, and you should see a NumPy version mismatch exeception.Screenshots
The text was updated successfully, but these errors were encountered: