[IPython-user] Can "import" module, then "run" cannot find it
Thomas Baker
tbaker@tbaker...
Sat Feb 20 21:37:07 CST 2010
Dear all,
I love IPython, especially (as a former awk user) now that I
have discovered the brilliant [1].
However, after extensive reading, Googling, and searching in
online documentation, I cannot understand why I should be able to
_import_ a module -- i.e., the module is in the path and is found --
but then not be able to _run_ it.
-- The pathname of the module is /home/tbaker/shawkle/shawkle.py.
-- The directory of test data is at /home/tbaker/shawkle/testdata.
This is where I want to run ipython (and shawkle), because
shawkle.py is designed to access data in the Working Directory.
This is what happens:
/home/tbaker/shawkle/testdata> ipython # I start IPython
Python 2.5.2. ... blah blah...
In [2]: import sys
In [3]: print sys.path
['', '/usr/bin', ... '/home/tbaker/shawkle'] # '/home/tbaker/shawkle' is in search path
In [4]: pwd # I am indeed in '/home/tbaker/shawkle/testdata'
Out[4]: '/home/tbaker/shawkle/testdata'
In [5]: import shawkle # "import" finds 'shawkle.py' with no problem
In [6]: edit shawkle # editing 'shawkle.py' works fine
Editing... done. Executing edited code... # vim shows me I am editing '~/shawkle/shawkle.py'
In [7]: edit shawkle.datashuffle # editing a particular function works fine
Editing... done. Executing edited code... # vim says I am editing ~/shawkle/shawkle.py'
In [8]: run shawkle
ERROR: File 'shawkle.py' not found. # So why can it now not find 'shawkle.py'??
In [9]: 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.
Any insights into this puzzling situation gratefully received...
Tom
[1] http://ipython.scipy.org/moin/Cookbook/StringListProcessing
--
Tom Baker <tbaker@tbaker.de>
More information about the IPython-user
mailing list