reload fails if module not in sys.path

Lonnie Princehouse finite.automaton at
Fri Oct 21 20:54:01 CEST 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/
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
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append('module_dir')
>>> import plugin
>>> sys.path.pop()
>>> 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/'>

More information about the Python-list mailing list