I have a python module packaged by distutils into a zipped egg installed in a custom prefix. If I set PYTHONPATH to contain that prefix’s site-packages directory, the egg is added to sys.path and the module can be imported. If I instead from within the script run site.addsitedir with the prefix’s site-packages directory, however, the egg is not added to sys.path and the module import fails. In both cases, the module’s site-packages directory ends up in sys.path.
Is this expected behavior? If so, is there any way to tell Python to process the .pth files in a given directory without setting an env var?
Adding some directory to
PYTHONPATHdoesn’t trigger processing of.pth-files in it. Therefore your zipped egg won’t be insys.path. You can import a module from the egg only if the egg itself is insys.path(parent directory is not enough).site.addsitedir()triggers processing of.pth-files if the directory hasn’t been seen yet so it should work.The behavior you described is the opposite of what should happen.
As a workaround you could add the egg to
sys.pathmanually:sys.path.insert(0, '/path/to/the.egg')