Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named django.core.management when using manage.py

I'm trying to run python manage.py runserver on a Django application I have and I get this error:

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

Here is the output of pip freeze | grep -i django to show I do in fact have Django installed:

Django==1.6.5 django-cached-authentication-middleware==0.2.0 django-cors-headers==1.1.0 django-htmlmin==0.7.0 django-static-precompiler==0.9 djangorestframework==2.3.14 

Also, trying to run /usr/local/bin/python2.7 manage.py runserver yields the same error.

like image 810
Zach Avatar asked May 22 '15 06:05

Zach


People also ask

How do I fix Django error module not found?

The Python "ModuleNotFoundError: No module named 'django'" occurs when we forget to install the Django module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install Django command.

Why does Python manage PY Runserver not work?

The site could be temporarily unavailable or too busy. Try again in a few moments. If you are unable to load any pages, check your computer's network connection. If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.

How do I know if Django is installed?

After the installation has completed, you can verify your Django installation by executing django-admin --version in the command prompt.


2 Answers

Possible issues that may cause your problem:

  1. PYTHONPATH is not well configured, to configure it you should do:

    export PYTHONPATH=/usr/local/lib/python2.7/site-packages 
  2. You forgot the line #!/usr/bin/env python at the beginning of manage.py

  3. If you're working on virtualenv you forgot to activate the virtual env to execute manage.py commands (You may have installed Django on your system but not on your virtualenv)

    source path/to/your/virtualenv/bin/activate 

    or

    workon env_name 
  4. You have Python 2.7 and Python 3.4 messing with the package

  5. You're using a very old Python 2.4 and you should tell the system to use your Python 2.7 with:

    alias python=python2.7 

Some times reinstalling/upgrading Django fix some of those issues.

You may want to execute

python -c "import django; print(django.get_version())" 

to check if Django is installed on your PC or your virtualenv if you're using one

You can find some other solutions in other similar questions:

  • Django import error
  • Django uwsgi error
  • Django module error
like image 97
AlvaroAV Avatar answered Sep 22 '22 02:09

AlvaroAV


To fix my problem I used the following line in my .zprofile:

export PYTHONPATH=/usr/local/lib/python2.7/site-packages 

I was trying to import Django and it couldn't be found, and doing the above solved the issue.

like image 27
Zach Avatar answered Sep 24 '22 02:09

Zach