Why does Python fail to run a program when I run it from its own directory? -
this not working:
numbers directory:
$ cat numbers.py import networkx nx ~/numbers $ python2.7 < numbers.py
this gives me few errors end like:
'module' object has no attribute 'number'
this working:
~ $ python2.7 < numbers/numbers.py
i installed networkx following these instructions: http://networkx.github.io/documentation/latest/install.html
download source (tar.gz or zip file) https://pypi.python.org/pypi/networkx/ or latest development version https://github.com/networkx/networkx/ unpack , change directory source directory (it should have files readme.txt , setup.py). run python setup.py install build , install (optional) run nosetests execute tests if have nose installed.
the tests run fine, don't understand why trivial program containing "import networkx nx" won't run.
what difference between these 2 situations ?
you passing in script on stdin, instead of on command line, python adds current working directory sys.path
instead of numbers
.
normally, python adds directory of script first element in sys.path
:
as initialized upon program startup, first item of list,
path[0]
, directory containing script used invoke python interpreter. if script directory not available (e.g. if interpreter invoked interactively or if script read standard input), path[0] empty string, directs python search modules in current directory first.
if having import problems, sounds if wrong module being imported; perhaps masking stdlib module 1 same name, locating in numbers
. rename module.
Comments
Post a Comment