[issue15434] __import__() problem in 3.3

Stefan Krah report at bugs.python.org
Mon Jul 23 13:02:12 CEST 2012


Stefan Krah <stefan-usenet at bytereef.org> added the comment:

It looks like distutils/command from the stdlib is searched first
despite the fact that the first path entry is '/home/stefan/tmp'.

If distutils/command is replaced with a/b, the import works:

$ pwd
/home/stefan/tmp
$ 
$ ls a/b/
__init__.py  xyz.py
$ ls distutils/command/
__init__.py  xyz.py
$ 
$ cat a/b/__init__.py 

import sys
sys.path.insert(0, '/home/stefan/tmp')
print(sys.path)

distutils_all = ['xyz']
__import__('a.b',globals(),locals(),distutils_all)


$ cat distutils/command/__init__.py 

import sys
sys.path.insert(0, '/home/stefan/tmp')
print(sys.path)

distutils_all = ['xyz']
__import__('distutils.command',globals(),locals(),distutils_all)



$ /home/stefan/usr/bin/python3.3 a/b/__init__.py 
['/home/stefan/tmp', '/home/stefan/tmp/a/b', '/home/stefan/usr/lib/python33.zip', '/home/stefan/usr/lib/python3.3', '/home/stefan/usr/lib/python3.3/plat-linux', '/home/stefan/usr/lib/python3.3/lib-dynload', '/home/stefan/.local/lib/python3.3/site-packages', '/home/stefan/usr/lib/python3.3/site-packages']
['/home/stefan/tmp', '/home/stefan/tmp', '/home/stefan/tmp/a/b', '/home/stefan/usr/lib/python33.zip', '/home/stefan/usr/lib/python3.3', '/home/stefan/usr/lib/python3.3/plat-linux', '/home/stefan/usr/lib/python3.3/lib-dynload', '/home/stefan/.local/lib/python3.3/site-packages', '/home/stefan/usr/lib/python3.3/site-packages']



$ /home/stefan/usr/bin/python3.3 distutils/command/__init__.py 
['/home/stefan/tmp', '/home/stefan/tmp/distutils/command', '/home/stefan/usr/lib/python33.zip', '/home/stefan/usr/lib/python3.3', '/home/stefan/usr/lib/python3.3/plat-linux', '/home/stefan/usr/lib/python3.3/lib-dynload', '/home/stefan/.local/lib/python3.3/site-packages', '/home/stefan/usr/lib/python3.3/site-packages']
Traceback (most recent call last):
  File "distutils/command/__init__.py", line 7, in <module>
    __import__('distutils.command',globals(),locals(),distutils_all)
ImportError: No module named 'distutils.command.xyz'

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15434>
_______________________________________


More information about the Python-bugs-list mailing list