Forums

No module named django.core.management

This problem may have been reported before, but I did not find an answer. Might be blind. Regardless, here's what happened in a brand new web app in a virtualenv created today:

python2.7 manage.py collectstatic                                                                       
Traceback (most recent call last):
  File "manage.py", line 7, in <module>
    from django.core.management import execute_from_command_line
ImportError: No module named django.core.management

Will be grateful for help.

That seems like a django version mismatch. What version of django and python are you expecting to be using?

Thanks for t he response, Conrad. I'm using Python 2.7 and Django==1.11.5. Works fine for local development.

This https://djangowaves.com/tips-tricks/fix-import-error-no-module-named-django-core-management/ says my virtualenv needs to be activated, but it looks active to me:

(gardens-virtualenv) 20:31 ~/valuenetwork (master)$

More clues:

(gardens-virtualenv) 12:55 ~/valuenetwork (master)$ python Python 2.7.12 (default, Oct 8 2019, 14:14:10) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import django Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named django

But previously

pip install -r requirements.txt
Collecting Django==1.11.5
  Downloading Django-1.11.5-py2.py3-none-any.whl (6.9 MB)
     |████████████████████████████████| 6.9 MB 13.6 MB/s

So I am confused...

So to try to make the previous post more clear:

  • As far as I can tell (from what the PythonAnywhere docs say), my virtualenv is active, and
  • Django 1.11.5 is installed in it.

But when I start Python and import django I get a "No module named django" error.

Ok, solved the problem. Sorry to bother the forum, but maybe somebody else won't know what I did not know.

Pip found an error when it tried to install one of the packages in requirements.txt, and so, while it looked to me like it had installed django, it had not actually installed anything. I should probably have known that, but didn't.

So I deleted all of the code that required that package and deleted it from requirements.txt. Pip installed everything happily, and no more missing module errors!

ah good catch! thanks for reporting back!