ImportError: No module named django.core.managemen

2019-02-02 04:45发布

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.

12条回答
老娘就宠你
2楼-- · 2019-02-02 05:16

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.

查看更多
劫难
3楼-- · 2019-02-02 05:18

The direct problem is that django package is missing. For me, as I was running django in virtualenv, this problem occurs after I rename my working directory.

Reinstalling the env worked for me.

查看更多
贼婆χ
4楼-- · 2019-02-02 05:20

I found that I could import the django module from the python interpreter, but django-admin.py could not import it when run from the command line.

I confirmed that I was using the python interpreter in my virtual environment.

I was using a 64-bit version of python. Uninstalling, and installing the 32-bit version, then re-creating my venv solved this for me.

查看更多
▲ chillily
5楼-- · 2019-02-02 05:23

in where your django file resides, check the first line of django-admin.py:

#!/usr/bin/env python

If you use python 3+, python here may refers python2 here. So check which python you install django with.

ls -l $(which -a python3)

If you do have python3 installed and not linked as python, change the first shebang line into

#!/usr/bin/env python3
查看更多
混吃等死
6楼-- · 2019-02-02 05:26

i solved this problem by installing django inside the virtual enviromment that i was working on

查看更多
祖国的老花朵
7楼-- · 2019-02-02 05:28

If you use virtualenv and run manage.py runserver in windows system, cmd will use system's python, not the python in virtualenv. Because If you install python in system, cmd will automatically use python that installed in system, not the python in virtualenv. So if you use virtualenv in Windows. you need run

>python .\manage.py runserver
查看更多
登录 后发表回答