reload fails if module not in sys.path

Lonnie Princehouse finite.automaton at gmail.com
Fri Oct 21 14:54:01 EDT 2005


It's not just load_module.  Reload fails on modules imported normally
if their paths are no longer in sys.path.

Easy to reproduce example:

bash$ mkdir module_dir
bash$ touch module_dir/plugin.py
bash$ python
Python 2.4.1 (#1, Sep 25 2005, 15:12:45)
[GCC 3.4.3 20041125 (Gentoo 3.4.3-r1, ssp-3.4.3-0, pie-8.7.7)] on
linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append('module_dir')
>>> import plugin
>>> sys.path.pop()
'module_dir'
>>> reload(plugin)    # plugin was imported correctly, but it can't be reloaded:
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: No module named plugin
>>>
>>> sys.modules['plugin']       # ... although it is sys.modules:
<module 'plugin' from 'module_dir/plugin.py'>




More information about the Python-list mailing list