Setting up an App and getting an import error

24 views
Skip to first unread message

jjander...@gmail.com

unread,
Apr 5, 2017, 12:28:23 PM4/5/17
to Django users

Hi,

I'm setting up a Django app using Django 1.10.3 and python 3.5.2. When I run the following command in my 3.5.2 virtual environment:

  python manage.py runserver

prior to entering the  app in INSTALLED_APPS in settings.py, my webpage comes up fine.


When I add the following line to INSTALLED_APPS:

    'util.siggy.apps.SiggyConfig',

I get the following error message:

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f47313e7620>
Traceback (most recent call last):
  File "/home/jja/testenv3.5/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/home/jja/testenv3.5/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 113, in inner_run
    autoreload.raise_last_exception()
  File "/home/jja/testenv3.5/lib/python3.5/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
    six.reraise(*_exception)
  File "/home/jja/testenv3.5/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/home/jja/testenv3.5/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/home/jja/testenv3.5/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/jja/testenv3.5/lib/python3.5/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/home/jja/testenv3.5/lib/python3.5/site-packages/django/apps/config.py", line 116, in create
    mod = import_module(mod_path)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'util.siggy'

In my project directory, I have a path .../project_dir/util/siggy/apps.py that has the class SiggyConfig defined in it.

It looks to me that python is not finding my util/siggy directory, but I'm not sure why. I included a print statement
in manage.py and it prinsts out the sys.path as:

['/home/jja/prog/dev/newSiggy',
 '/home/jja/testenv3.5/lib/python3.5/site-packages/django_classy_tags-0.8.0-py3.5.egg',
 '/home/jja/testenv3.5/lib',
 '/usr/lib/python35.zip',
 '/usr/lib/python3.5',
 '/usr/lib/python3.5/plat-x86_64-linux-gnu',
 '/usr/lib/python3.5/lib-dynload',
 '/home/jja/testenv3.5/lib/python3.5/site-packages']


where /home/jja/prog/dev/newSiggy is the path to my Django project root.

The full path to my app is /home/jja/prog/dev/newSiggy/util/siggy/apps.py.

It is a mystery to my why python cannot find 'util.siggy'.

I've looked on the web and have not found a case that seems to match mine (some are close). I have tried changing a few
path related settings, but so far, no success.

Any suggestions on what to try next?

Jim A.

 

Nate Granatir

unread,
Apr 7, 2017, 1:40:04 PM4/7/17
to Django users
I may be speaking a bit out of my depth here, but I wonder if it's maybe because you haven't created __init__.py files in the directories? I believe Django (well, Python), requires an empty __init__.py file in directories when loading them as modules:

If it's not that, then I have no idea!

Nate
Reply all
Reply to author
Forward
0 new messages