I have a clean virtual machine with XP SP3 32-bit and ActivePython 2.7.2 32-bit community edition, current dir is "C:\test". I have placed sitecustomize.py with "print( 'dir1' )" code indie "C:\test\dir1" and sitecustomize.py with "print( 'dir2' )" code indie "C:\test\dir2".
If i set PYTHONPATH to dir1 or dir2, corresponding sitecustomize.py is executed:
C:\test> set PYTHONPATH=C:\test\dir1\
C:\text> python
dir1
>>>exit()
C:\test> set PYTHONPATH=C:\test\dir2\
C:\text> python
dir2
But if i add both dirs to pythonpath, only sitecustomize.py of first dir is executed:
C:\test> set PYTHONPATH=C:\test\dir1\;C:\test\dir2\
C:\text> python
dir1
>>>exit()
C:\test> set PYTHONPATH=C:\test\dir2\;C:\test\dir1\
C:\text> python
dir2
So is it possible to have multiple dirs in PYTHONPATH and multiple sitecustomize.py or i'm limited to one? Documentation states that i can have many dirs in PYTHONPATH, but it don't say anything about sitecustomize.py
Yes, you can list multiple directories in PYTHONPATH.
sitecustomize is a module that automatically gets imported when the interpreter starts up. Consequently, if there are several sitecustomize.py on your PYTHONPATH, only the first one will be loaded.
The process is described in the documentation:
After these path manipulations, an attempt is made to import a module named
sitecustomize, which can perform arbitrary site-specific customizations. It is typically created by a system administrator in the site-packages directory. If this import fails with anImportErrorexception, it is silently ignored.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With