problem with packages and path

Paul Boddie paul at
Wed Aug 27 19:00:34 CEST 2008

On 27 Aug, 18:44, Daniel <daniel.watr... at> wrote:
> I'm writing some unit tests for my python software which uses
> packages.  Here is the basic structure:
> mypackage


>   unittests
> within I would expect to be able to "import
> mypackage.unittests.test1".  In fact within PyScripter this works as
> expected.  However, when I execute the code from the command line, I
> get the following error:
> ImportError: No module named mypackage.unittests.test1

One thing to note: if you are running directly (which you
don't mention explicitly) then even if you do so from the directory
containing the root of the package hierarchy (mypackage), it will be
the directory containing (unittests) which will appear on
the PYTHONPATH/sys.path. Sometimes it's easy to take this behaviour
for granted when running programs.

A question: what happens if you prepend the directory containing the
root of package hierarchy to sys.path using insert (at element 0)
rather than append?


More information about the Python-list mailing list