0

I can't seem to get my manage.py script to recognize the django module. pip install req/dev.txt installs all of the modules I would expect it to into my my python virtual environment (stored at .venv).

I think I've narrowed it down to a problem with either my $PYTHON_PATH or with my pip requirements files. I've looped through sys.path, and I see that one of the values points to a folder in .venv that I can confirm contains the django module.

I'm unfortunately at a loss. I've searched through a dozen related questions on Stack Overflow and have yet to find a solution that works. Does anyone have any clues to point me in the right direction?

Error message:

$ python manage.py syncdb

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/nathan/www/myapp/.venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/Users/nathan/www/myapp/.venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 312, in execute
    django.setup()
  File "/Users/nathan/www/myapp/.venv/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/nathan/www/myapp/.venv/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/Users/nathan/www/myapp/.venv/lib/python2.7/site-packages/django/apps/config.py", line 119, in create
    import_module(entry)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named django

Contents of reqs/dev.txt

-r common.txt
django-debug-toolbar==1.3.2

Contents of reqs/common.txt

django==1.8
Fabric==1.10.2
ShopifyAPI>=2.1.5
Sphinx==1.3.1
celery>=3.1.20
django-compressor>=1.5
django-toolbelt>=0.0.1
jdcal>=1.0
kombu>=3.0.35
openpyxl==2.2.5
python-dateutil>=2.4.2
psycopg2>=2.5
requests==2.7.0
whitenoise==2.0
shippo==1.4.0

Contents of manage.py:

#!/usr/bin/env python
import os
import sys    

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings.dev")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)
Nathan Bell
  • 2,364
  • 2
  • 18
  • 16
  • 3
    You should create a virtualenv anyway for your development, doing so (and using it) should solve your issues – Sayse Feb 13 '17 at 13:09
  • 1
    Thank you - while I did have a venv running, I realized that I should verify it was being used (it was), which led me to realize I should dive into the stack trace and just start printing things to debug on which input things are breaking. That led me to my solution, written below! Thank you – Nathan Bell Feb 13 '17 at 20:25

1 Answers1

2

Problem solved after a good night's rest.

The issue was that my INSTALLED_APPS had a reference to kombu.transport.django, which seems to be a completely unnecessary dependency we added for celery. More information on that here: Celery, kombu and django - import error

How I discovered the solution, in case the debugging technique helps anyone else:

I started by diving into the stack trace. I (temporarily) modified the files in .venv/ to add print statements for the input variables until I found my first clue in populate() in .venv/lib/python2.7/site-packages/django/apps/registry.py

Printing through each entry in populate() allowed me to see that the package that was breaking was kombu.transport.django and NOT the django module proper. Deleting that entry from my INSTALLED_APPS solved the problem.

To cleanup I reverted the files in .venv/ by removing my print statements and I was off and running!

Community
  • 1
  • 1
Nathan Bell
  • 2,364
  • 2
  • 18
  • 16