Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python package import error

I'm trying to package my modules, but I can't seem to get it working.

My directory tree is something like the following:

snappy/
    __init__.py
    main/
        __init__.py
        main.py
        config.py
        ...
    ...      

and the code I'm using is

from snappy.main.config import *

I'm getting the error:

ImportError: No module named snappy.main.config

Any ideas what's going wrong? This is using Python 2.5 on Ubuntu 8.10.

Thanks in advance for your help.

like image 702
Donald Harvey Avatar asked Feb 25 '26 08:02

Donald Harvey


1 Answers

It depends on where your script using the import resides and your system PYTHONPATH. Basically, to have that import working you should run your script (the one having the import) in the parent directory of snappy or your script should change sys.path to include it.

./alex

like image 180
alexpopescu Avatar answered Feb 26 '26 20:02

alexpopescu