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.sitecustomizeis a module that automatically gets imported when the interpreter starts up. Consequently, if there are severalsitecustomize.pyon yourPYTHONPATH, only the first one will be loaded.The process is described in the documentation: