ImportError raised in script, not interactive session.

Adam Blinkinsop hackerblinks at gmail.com
Mon Jul 31 18:42:04 EDT 2006


I'm writing a set of modules to monitor remote system services, and I'm
having a problem running my test scripts.  When I pass the scripts into
python, like so:

--
$ PYTHONPATH="${TARGET_DIR}" python test.py
--

I get an ImportError:

--
Traceback (most recent call last):
  File "./test.py", line 6, in ?
    from overwatch.view import console
ImportError: No module named view
--

However, when I load up an interactive Python session:

--
$ PYTHONPATH="${TARGET_DIR}" python
--

I can do the exact same import statement with no problem:

--
Python 2.4.3 (#1, Jul 28 2006, 09:40:08)
[GCC 3.4.4 (Gentoo 3.4.4-r1, ssp-3.4.4-1.0, pie-8.7.8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from overwatch.view import console
>>> dir(console)
['Daemon', 'UI', '__builtins__', '__doc__', '__file__', '__name__',
'datetime']
--

My package directory is arranged under ${TARGET_DIR} as prescribed in
the Python docs:
overwatch/
..__init__.py
..[etc.]
..view/
....__init__.py
....console.py
....[etc.]

All modules involved are my own, and I'm setting PYTHONPATH so I can
test with the package installed in my home directory (which I use
distutils to do).  I've checked online, and double-checked the Python
docs to make sure my modules are arranged properly, and it all looks
alright.  Any ideas?




More information about the Python-list mailing list