This summarizes a group chat discussion and additionally documents Cursor-based verification:
Problem
When cuda.pathfinder.load_nvidia_dynamic_lib searches for NVIDIA dynamic libraries in site-packages, it currently searches in the following order unconditionally:
- User site-packages (
site.getusersitepackages())
- Site packages from
site.getsitepackages() (which includes both virtual environment and system site-packages)
This ordering causes issues in a venv created with --system-site-packages: according to PEP 405 the correct search order should be (verified as explained below):
- Virtual environment site-packages
- User site-packages
- System site-packages
Cursor-based verification
PEP 405 (Virtual Environments):
- States that in a
venv with --system-site-packages, system site directories are added after virtual environment site directories.
- Notes that PEP 370 user-level site-packages are considered part of system site-packages for
venv purposes.
PEP 370 (User Site-Packages):
- States that user-site-packages are added before system site-packages (outside
venv context).
Actual Python Behavior (verified by test):
In a venv with --system-site-packages, Python's sys.path order is:
- Virtual environment site-packages
- User site-packages
- System site-packages
This confirms that the correct search order described above matches both PEP 405, PEP 370, and Python's actual behavior.
References
This summarizes a group chat discussion and additionally documents Cursor-based verification:
Problem
When
cuda.pathfinder.load_nvidia_dynamic_libsearches for NVIDIA dynamic libraries in site-packages, it currently searches in the following order unconditionally:site.getusersitepackages())site.getsitepackages()(which includes both virtual environment and system site-packages)This ordering causes issues in a
venvcreated with--system-site-packages: according to PEP 405 the correct search order should be (verified as explained below):Cursor-based verification
PEP 405 (Virtual Environments):
venvwith--system-site-packages, system site directories are added after virtual environment site directories.venvpurposes.PEP 370 (User Site-Packages):
venvcontext).Actual Python Behavior (verified by test):
In a
venvwith--system-site-packages, Python'ssys.pathorder is:This confirms that the correct search order described above matches both PEP 405, PEP 370, and Python's actual behavior.
References