[IPython-user] (no subject)
Fernando Perez
fperez.net@gmail....
Wed Jul 16 19:33:30 CDT 2008
On Sun, Jul 13, 2008 at 6:59 AM, kevin beckford <kevin@lazyweb.ca> wrote:
> I am struggling with a hopefully simple problem in ipython
> .0.8.4. Basically, I'm finding that I need to exit the interpreter when i
> add a new module to site-packages. I've tried reload et al, but these do
> not seem to have the effect i want, ( that effect being that i can stay in
> the interpreter, adding new modules to the python path , and having them
> available to me )
> for example: I have a machine:
> I run ipython and try:
> import django
> This does not work because I've forgotten to actually install it.
> I screen over to my admin screen, install the module and then in order to
> get ipython to re-read the modules, I'm forced to exit and enter ipython
> again. Since I run ipython out of my .screenrc this is a bit inconvenient.
> How can i avoid this?
Mmh, I'm afraid that I'll need a more reproducible test case than
that, with the actual tracebacks, to give you a suggestion. Because
the generic case of "import foo, foo missing, install foo, repeat
import foo" does work:
#foobarz2.py doesn't exist:
In [5]: import foobarz2
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/home/fperez/<ipython console> in <module>()
ImportError: No module named foobarz2
# go to admin screen, add foobarz2.py into $PYTHONPATH directory:
In [6]: import foobarz2
Here!
# The 'Here!' was printed by foobarz2.py.
So as you can see, for this simple case, it does work. What does NOT
work is the following:
1. import foo: raises ImportError because *IT* imports 'bar', which is missing
2. you go and install 'bar'
3. you repeat the 'foo' import.
That can fail, because a broken, half-imported foo is left in
sys.modules. At that point you can try to do
import bar
reload(foo)
You can also try IPython's dreload():
dreload(foo)
which attempts a recursive reload.
But yes, in summary, module reloading in python in general is a bit of
an unpleasant mess.
Cheers,
f
More information about the IPython-user
mailing list