problem with packages and path

Daniel daniel.watrous at gmail.com
Fri Aug 29 19:08:25 CEST 2008


On Aug 28, 2:28 am, "Marco Bizzarri" <marco.bizza... at gmail.com> wrote:
> On Wed, Aug 27, 2008 at 6:44 PM, Daniel <daniel.watr... at gmail.com> wrote:
> > Hello,
>
> > I'm writing some unit tests for my python software which uses
> > packages.  Here is the basic structure:
>
> > mypackage
> >  __init__.py
> >  module1
> >    __init__.py
> >    mod1.py
> >  module2
> >    __init__.py
> >    mod2.py
> >  unittests
> >    __init__.py
> >    alltests.py
> >    test1.py
> >    test2.py
>
> > within alltests.py 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
>
> 1) What is the command you're using to run the alltest.py module?
>
> 2) what is the result of:
>    - python -c "import mypackage"
>   - python -c "import mypackage.unittests"
>
> Regards
> Marco
>
> --
> Marco Bizzarrihttp://iliveinpisa.blogspot.com/

I have tried running both commands above from the mypackage directory
and unittests directory.  I get the following response universtally.

C:\mypackage>dir
 Volume in drive C is Default

 Directory of C:\mypackage

08/29/2008  11:04 AM    <DIR>          .
08/29/2008  11:04 AM    <DIR>          ..
08/29/2008  11:05 AM    <DIR>          module1
08/29/2008  11:05 AM    <DIR>          module2
08/29/2008  11:06 AM    <DIR>          unittests
08/29/2008  11:04 AM                 0 __init__.py
               1 File(s)              0 bytes
               5 Dir(s)  55,402,070,016 bytes free

C:\mypackage>dir unittests
 Volume in drive C is Default

 Directory of C:\mypackage\unittests

08/29/2008  11:06 AM    <DIR>          .
08/29/2008  11:06 AM    <DIR>          ..
08/29/2008  11:05 AM                 0 alltests.py
08/29/2008  11:05 AM                 0 test1.py
08/29/2008  11:05 AM                 0 test2.py
08/29/2008  11:04 AM                 0 __init__.py
               4 File(s)              0 bytes
               2 Dir(s)  55,401,988,096 bytes free

C:\mypackage>python -c "import mypackage"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named mypackage

C:\mypackage>python -c "import mypackage.unittests"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named mypackage.unittests



More information about the Python-list mailing list