Django importerror

I created my own Django directory structure application

/appname __init__.py models.py /submodule1 __init__.py a.py 

Inside a.py I have the following import

 from ..models import Something 

This is normal if I have /appname inside my /djangoproject folder, but when I install the application in Python site packages (via setup.py that I created), all hell breaks up and a.py cannot import Something longer with following error:

 ImportError: cannot import name Something 

Here is setup.py:

 from distutils.core import setup setup(name='appname', version='0.1', packages=['appname', 'appname.contrib'], ) 
+6
source share
2 answers

It turns out that it was a circular import error. models.py imported a.py and a.py imported models.py .

Breaking this circle solved the import problem, but now it's time to figure out how to make a lazy evaluation in Python :-)

+5
source

Put an empty file named: __init__.py inside / submodule 1 so that Python can parse it as a module. This should help. Same thing in / appname - there should also be an __init__.py file

+2
source

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


All Articles