Forums

Modules not found - can't run makemigrations/migrate

I'm trying to go through the whole Deploying an existing Django project on PythonAnywhere tutorial. I followed steps 1 to 4 but am now stuck with the database setup. Running ./manage.py migrate always throws an error, saying a module was not found. Removing it from my settings.py only results in the following module to be named as missing. E. g.:

Traceback (most recent call last):
  File "./manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute
    django.setup()
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 94, in create
    module = import_module(entry)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named django_extensions

Running python3.6 ./manage.py migrate results in a similar error:

Traceback (most recent call last):
  File "./manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
    django.setup()
  File "/usr/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/lib/python3.6/site-packages/django/apps/registry.py", line 89, in populate
    app_config = AppConfig.create(entry)
  File "/usr/lib/python3.6/site-packages/django/apps/config.py", line 90, in create
    module = import_module(entry)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'django_extensions'

My WSGI file looks like this:

import os
import sys

path = '/home/Everlong/icdb'
if path not in sys.path:
    sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'icdb.settings'

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

As per the tutorial my django project folder is not part of the virtualenv. I have to say, I'm pretty new to coding, Django and Python and can't seem to wrap my head around this. I installed all files from my requirements.txt to the virtualenv, my web app was set up with Python 3.6 - where does this error come from? Any help would be greatly appreciated. Thanks in advance!

  1. Does your code work on your local machine?
  2. Please show your code for INSTALLED_APPS in 'settings.py'. Did you add all apps to 'INSTALLED_APPS'?
  3. Do you have an empty `_init_.py' file in the app folder?
  1. Yes, my code works on my local machine, though I'm not using a virtualenv.
  2. Yes, I cloned it directly from my git and didn't make any chances to the INSTALLED_APPS.

    INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.sites', 'django.contrib.flatpages', 'django_extensions', 'crispy_forms', 'rest_framework', 'cocktaildb', 'django_filters', 'widget_tweaks', ]

  3. Yes, there is an empty init.py file in the app folder.

have you pip installed django-extensions? which version of python are you using (and are you using a virtualenv?) vs which version is django-extensions installed into?

I followed the steps in the tutorial. Firstly I cloned my git.

Secondly I created a virtualenv (running mkvirtualenv --python=/usr/bin/python3.6 icdb-virtualenv).

Thirdly I ran pip install -r /home/Everlong/icdb/requirements.txt while still being inside my virtualenv. After that I deactivated the virtualenv and continued with "Setting up your Web app and WSGI file". And I entered the name of the virtualenv in the Virtualenv section on the web tab.

Did you reload the website using the button at the top of the "Web" page after entering the name of the virtualenv?

Yep, did that too.

Are you sure you're running those management commands in the virtualenv you set up? The easiest way to make sure that you are is to start the bash console using the link on the "Web" page labelled "Start a console in this virtualenv".

Oh wow. Don't know how I could've been this stupid. I didn't run those commands in the virtualenv. Worked like a charm when I did now. Thanks again!

Excellent!

Thanks issue resolved with "Start a console in this virtualenv"

even if I ran all commands in the virtualenv I set up I still get the same error as in this topic. what should I try different

@ Tuna88 We need more details.What is the exact error you get