Python package import error

I am trying to pack my modules, but I cannot get it to work.

My directory tree is as follows:

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

and the code that I use

from snappy.main.config import *

I get an error message:

ImportError: No module named snappy.main.config

Any ideas what goes wrong? This uses Python 2.5 on Ubuntu 8.10.

Thanks in advance for your help.

+3
source share
2 answers

It depends on where your script is located using the import and your PYTHONPATH system. Basically, to work with import, you must run your script (the one who has the import) in the snappy parent directory or your script must modify sys.path to enable it.

./Alex

+5
source

snappy sys.path? , , , .

+5

Source: https://habr.com/ru/post/1703690/


All Articles