Welcome, guest | Sign In | My Account | Store | Cart

Since Python 2.5 the automatic import of the module "sitecustomize.py" in the directory of the main program is not supported any more (even if the documentation says that it is). Putting this little script named "sitecustomize.py" in the default Python path like in "site-packages" should solve this problem.

Python, 8 lines
1
2
3
4
5
6
7
8
#!/usr/local/bin/python
# -*- coding: ISO-8859-1 -*-

import sys
import os
sys.path = [os.getcwd()] + sys.path
import sitecustomize
reload(sitecustomize)

Since Python 2.5 the current working directory seems to be added to sys.path somewhere latter after importing the file "site" (see Python documentation for detail). So the "sitecustomize.py" file is just found on the default path. So we add this small file, which adds the current working directory to the sys.path. Then we import sitecustomize again, but this will have no effect because we are already in it. So we reload the module and then it will use the new path to look for sitecustomie. A minor side effect is that sitecustomize will sometimes be loaded twice, but a deadlook seems not to happen.