[IPython-user] Can "import" module, then "run" cannot find it
Mon Feb 22 00:13:58 CST 2010
> The reason for your confusion is that sys.path is the path used for the
> python import mechanism but the run magic of ipython only looks in the
> current directory.
Okay - that does explain it - thank you!
So if I want to run code, within ipython, but from a directory
other than the directory where the code is located, I cannot use
%run. But I guess if I %edit the code, %edit will find it wherever
it is in my path, and when I exit the editor, the code will be
executed. Would that be any different than using %run to execute
On Mon, Feb 22, 2010 at 08:05:13PM +0100, Jörgen Stenarson wrote:
> > This is what happens:
> > /home/tbaker/shawkle/testdata> ipython # I start IPython
> > Python 2.5.2. ... blah blah...
> > In : import sys
> > In : print sys.path
> > ['', '/usr/bin', ... '/home/tbaker/shawkle'] # '/home/tbaker/shawkle' is in search path
> > In : pwd # I am indeed in '/home/tbaker/shawkle/testdata'
> > Out: '/home/tbaker/shawkle/testdata'
> > In : import shawkle # "import" finds 'shawkle.py' with no problem
> > In : edit shawkle # editing 'shawkle.py' works fine
> > Editing... done. Executing edited code... # vim shows me I am editing '~/shawkle/shawkle.py'
> > In : edit shawkle.datashuffle # editing a particular function works fine
> > Editing... done. Executing edited code... # vim says I am editing ~/shawkle/shawkle.py'
> > In : run shawkle
> > ERROR: File 'shawkle.py' not found. # So why can it now not find 'shawkle.py'??
> > In : run ../shawkle.py # Giving a relative reference seems to work...
> > My question is: how is it that IPython can find shawkle.py to import it,
> > edit it, and execute the edited code, but is unable to find the same file
> > in order to "run" it?
> > I have tried adding '~/shawkle' to the search path as well
> > (using sys.path.append), but that does not fix the problem.
> > I have also tried putting a special PYTHONPATH in my bash
> > profile, but that also does not seem to make a difference, and I
> > have commented it out (leaving just PATH).
> > I use python 2.5.2-1 and cygwin 1.7.1-1 with Windows XP.
> IPython-user mailing list
Tom Baker <email@example.com>
More information about the IPython-user