Double symlinking breaks module import
Andrew Dalke
adalke at mindspring.com
Sun Aug 24 13:26:41 EDT 2003
Csaba Henk:
> The symlink can't be wrong because the python program itself (to which the
> symlinks refer) starts up; it just doesn't find the module. This question
is
> related to importing modules, and the list of dirs in which the module
> seeked is a Python internal, so it does not depend only on file functions.
> How symlinking affect the module search path?
Ahh, I think I know what's causing this. Here's how sys.path gets
set, from the documentation for the sys module.
] As initialized upon program startup, the first item of this list, path[0],
is
] the directory containing the script that was used to invoke the Python
] interpreter. If the script directory is not available (e.g. if the
interpreter
] is invoked interactively or if the script is read from standard input),
] path[0] is the empty string, which directs Python to search modules
] in the current directory first. Notice that the script directory is
inserted
] before the entries inserted as a result of PYTHONPATH
%mkdir dir1
%cat > dir1/blah.py
import sys
print "path[0] ==", sys.path[0]
%mkdir dir2
%ln -s ../dir1/blah.py dir2
%cat dir2/blah.py
import sys
print "path[0] ==", sys.path[0]
%python dir1/blah.py
path[0] == dir1
%python dir2/blah.py
path[0] == dir2/../dir1
%
%ln -s dir2/blah.py .
%python blah.py
path[0] == dir2
%
So there's some interaction here between the OS and Python (the
details of which I don't know) that causes the problem you see.
If I had to hazard a guess, there's probably a use of lstat once
when it should be recursively.
Feel free to submit this as a bug.
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list