sys.path and os.chdir
Ugo_DiGirolamo at InVision.iip.com
Fri Aug 23 15:22:59 CEST 2002
I have the following script:
## START test0.py
import os, sys
cwd = os.getcwd()
## END test0.py
## START test1.py
## END test1.py
test0.py is in D:\temp
test1.py is in D:\temp\temp1
I try to run the script as follows:
['D:\\temp', 'C:\\', 'D:\\python22\\DLLs', 'D:\\python22\\lib',
Traceback (most recent call last):
File "D:\temp\test0.py", line 8, in ?
ImportError: No module named test1
And as follows:
['', 'D:\\Temp', 'D:\\python22\\DLLs', 'D:\\python22\\lib',
Obviously the problem is caused by the fact that my sys.path contains
'' when I invoke the script from the same dir, but contains the full
path of the script 'D:\\temp' when I invoke the script from another
So, calling os.chdir has no longer any effect when running the script
from another dir.
In order to fix it, I've tried to add '.' to my PYTHONPATH but it does
not solve the problem.
I guess I might explicitly append '' to sys.path in the script, but
this is not exactly a desirable solution (I would need to do it on
Am I doing anything wrong?
BTW, I'm running
Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on
More information about the Python-list