473,388 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Double symlinking breaks module import

Hello!

I use Python 2.2.2 on Linux. I met the following issue:

Say I have the module mymod and the script myprog.py in /mydir.
myprog.py imports mymod. If I create a symlink
/foo/myprog2.py -> /mydir/myprog.py, everything works as it should,
invoking any of /foo/myprog2.py /mydir/myprog.py work in the same way. But
if I create another symlink myprog3.py -> myprog2.py, and then I invoke
myprog3.py, I get compliances that mymod is not found.

Is it a bug or policy?

--
Csaba

Set theory is the LSD of mathematics
Jul 18 '05 #1
1 1497
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
da***@dalkescientific.com
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Paul Rubin | last post by:
That's what the Python style guides advise. They don't seem to like def frob(x): import re if re.search('sdfxyz', x): ... instead preferring that you pollute your module's global namespace...
5
by: dody suria wijaya | last post by:
I found this problem when trying to split a module into two. Here's an example: ============== #Module a (a.py): from b import * class Main: pass ============== ==============
4
by: Bo Peng | last post by:
Dear list, What I would like to do is something like: In myModule.py ( a wrapper module for different versions of the module), if lib == 'standard': from myModule_std import * elsif lib ==...
7
by: Brian van den Broek | last post by:
Hi all, I'm posting partly so my problem and solution might be more easily found by google, and partly out of mere curiosity. I've just spent a frustrating bit of time figuring out why pydoc...
0
by: Dathan Vance Pattishall | last post by:
------=_NextPart_000_0008_01C360E9.83F20A70 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit What would be the draw backs of symlinking tables from say ...
8
by: Jim | last post by:
Is there some easy way to split a line, keeping together double-quoted strings? I'm thinking of 'a b c "d e"' -- .. I'd also like 'a b c "d \" e"' -- which omits any s.split('"')-based...
3
by: kwatch | last post by:
What is the condition of module name which is available in 'from .. import ..' statement ? ---------------------------------------- import os print os.path # <module 'posixpath'...
1
by: Aljosa Mohorovic | last post by:
i have a working MySQLdb module (/usr/lib/python2.4/site-packages/ MySQL_python-1.2.2-py2.4-linux-i686.egg), using it without problems. "clean shell" after login: python -c "import MySQLdb"...
0
by: Fredrik Lundh | last post by:
Jeff Dyke wrote: so how did that processing use the "mymodulename" name? the calling method has nothing to do with what's considered to be a local variable in the method being called, so...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.