New submission from Jason Howlett <jagua...@gmail.com>: This error is observed in Python 2.7.2.
Steps to recreate problem: 1) Create directory ~/pytest. 2) Untar Python 2.7.2 sources into ~/pytest 3) configure, build, and install with --prefix=~/pytest/pyinstall 4) mkdir -p ~/pytest/other/bin 5) cd ~/pytest/other/bin 6) ln -s ../../pyinstall/bin/python 7) cd ~/pytest 8) ln -s other/bin bin 9) bin/python This will result in the following exception: Traceback (most recent call last): File "/home/jason/pytest/bin/../../pyinstall/lib/python2.7/site.py", line 564, in <module> main() File "/home/jason/pytest/bin/../../pyinstall/lib/python2.7/site.py", line 546, in main known_paths = addusersitepackages(known_paths) File "/home/jason/pytest/bin/../../pyinstall/lib/python2.7/site.py", line 279, in addusersitepackages user_site = getusersitepackages() File "/home/jason/pytest/bin/../../pyinstall/lib/python2.7/site.py", line 254, in getusersitepackages user_base = getuserbase() # this will also set USER_BASE File "/home/jason/pytest/bin/../../pyinstall/lib/python2.7/site.py", line 243, in getuserbase from sysconfig import get_config_var ImportError: No module named sysconfig Placing 'print sys.path' on line 242 of site.py prints out something like this: ['/home/jason/pyinstall/lib/python27.zip', '/home/jason/pyinstall/lib/python2.7', '/home/jason/pyinstall/lib/python2.7/plat-linux2', '/home/jason/pyinstall/lib/python2.7/lib-tk', '/home/jason/pyinstall/lib/python2.7/lib-old', '/home/jason/pyinstall/lib/python2.7/lib-dynload'] Notice that the root directory is /home/jason/pyinstall instead of the correct value /home/jason/pytest/pyinstall. Now, on line 65 of site.py, add import sysconfig. For some reason this works at this point in site.py, but not down on line 243. In sysconfig.py, at line 94, add the following: print 'SYSCONFIG:', sys.exec_prefix, _EXEC_PREFIX This will print the following: SYSCONFIG: /home/jason/pytest/bin/../../pyinstall /home/jason/pyinstall Line 93 of sysconfig.py is a call to normpath that collapses the path. The root of this problem is that the value of sys.exec_prefix is not correct. The value it has will work fine if ls'ing it in a shell as it handles the symlink /home/jason/pytest/bin properly. Path calculations internal to python, however, do not end up with the correct results. I believe the fix to this problem is to modify Modules/getpath.c, starting at line 488, and instead of looking only for a symlink in the python executable, also look for a link in any of the path elements leading up to the executable. Detecting and expanding these out should result, in this example, with sys.exec_prefix being /home/jason/pytest/pyinstall and the correct behavior in sysconfig, site, etc. ---------- components: Interpreter Core messages: 145582 nosy: Jason.Howlett priority: normal severity: normal status: open title: Multi-layered symlinks cause runtime error. sys.path is malformed. type: crash versions: Python 2.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue13184> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com