Generated code that is exec-ed (to simulate import) cannot import os.path??

Irmen de Jong irmen at -NOSPAM-REMOVETHIS-xs4all.nl
Fri Nov 28 13:28:58 CET 2003


Michael Hudson wrote:
>>What's going on? Why can't it find os.path?
> 
> 
> Dunno.  Two things to try:
> 
> 1) using new.module instead of the imp function

Tried it, no difference. I think they are equivalent.

> 2) run python -v

A relevant piece of the trace is found below, using
the same code that I posted before. I've done this already
but couldn't find anything that helps me understand why
os.path cannot be imported.


--Irmen


[.... partial 'python -v dynimport.py' output....]
got code...
importing random
# /usr/local/lib/python2.3/random.pyc matches 
/usr/local/lib/python2.3/random.py
import generated.random # precompiled from 
/usr/local/lib/python2.3/random.pyc
dlopen("/usr/local/lib/python2.3/lib-dynload/math.so", 2);
import generated.math # dynamically loaded from 
/usr/local/lib/python2.3/lib-dynload/math.so
dlopen("/usr/local/lib/python2.3/lib-dynload/_random.so", 2);
import generated._random # dynamically loaded from 
/usr/local/lib/python2.3/lib-dynload/_random.so
dlopen("/usr/local/lib/python2.3/lib-dynload/time.so", 2);
import generated.time # dynamically loaded from 
/usr/local/lib/python2.3/lib-dynload/time.so
importing os
# /usr/local/lib/python2.3/os.pyc matches /usr/local/lib/python2.3/os.py
import generated.os # precompiled from /usr/local/lib/python2.3/os.pyc
import sys # previously loaded (sys)
import posix # previously loaded (posix)
import posix # previously loaded (posix)
# /usr/local/lib/python2.3/posixpath.pyc matches 
/usr/local/lib/python2.3/posixpath.py
import generated.posixpath # precompiled from 
/usr/local/lib/python2.3/posixpath.pyc
import sys # previously loaded (sys)
# /usr/local/lib/python2.3/stat.pyc matches /usr/local/lib/python2.3/stat.py
import generated.stat # precompiled from /usr/local/lib/python2.3/stat.pyc
import posix # previously loaded (posix)
Traceback (most recent call last):
   File "dynimport.py", line 18, in ?
     exec code in newmod.__dict__
   File "<generated code>", line 5, in ?
   File "/usr/local/lib/python2.3/os.py", line 131, in ?
     from os.path import curdir, pardir, sep, pathsep, defpath, extsep, 
altsep
ImportError: No module named path
# clear __builtin__._
# clear sys.path
# clear sys.argv

[.... end snipped...]





More information about the Python-list mailing list