No Module named django.core

2020-01-24 11:35发布

I have updated to latest Django version 1.0.2 after uninstalling my old Django version.But now when I run django-admin.py I get the following error. How can I resolve this?

Traceback (most recent call last):
  File "C:\Python25\Lib\site-packages\django\bin\django-admin.py", line 2, in <module>
    from django.core import management
ImportError: No module named django.core

标签: python django
25条回答
三岁会撩人
2楼-- · 2020-01-24 11:50

I encountered this problem today, it turned out that I had C:\Python26 in my path and .py files were associated to Python 3.1. Repairing the proper version of Python, either through Programs and Features or by running the .msi, will fix the associations.

查看更多
我想做一个坏孩纸
3楼-- · 2020-01-24 11:50

I had the same problem, it was clear that I had a PYTHONPATH configuration issue. The solution is quite simple, just create a file with this name django.pth in your PYTHONHOME\Lib\site-packages directory where PYTHONHOME is the directory where Python is installed (mine is: C:\Python27). Add the following line to the django.pth file:

PYTHONHOME\Lib\site-packages\django

Of course you have to change PYTHONHOME to your Python's installation directory as I explained.

Note that you can edit the django.pth to include any directory that you want to be included in the PYTHONPATH. Actually, you can name that file as you wish, path.pth for example if you want it to be more general and to include several directory paths.

查看更多
对你真心纯属浪费
4楼-- · 2020-01-24 11:55

The simplest solution though not the most elegant is to copy the django-admin.py from the Scripts folder. The Scripts folder will be found under your Python installation . On my computer it is in C:\Python26\Scripts. Then paste the django-admin.py into the folder you are trying to run the file from. It is true that the use of the System path will give flexibility. This is a particular solution if you are in a hurry. Then type for instance python django-admin.py startproject fluffyteaspoons and you will create the project fluffyteaspoons

查看更多
Evening l夕情丶
5楼-- · 2020-01-24 11:55

In my case, I'm on OS X Lion and I've installed Python with homebrew I was getting the same error, but none of the solutions posted here helped me. In my case I just had to edit the script:

vim /usr/local/share/python/django-admin.py

And I noticed that the first line was wrong, as it was pointing to the system's python installation:

#!/usr/bin/python

I just modified it to point to homebrew's installation:

#!/usr/local/bin/python

And it worked :)

查看更多
萌系小妹纸
6楼-- · 2020-01-24 11:56

As usual, an install script failed to set world read/execute permissions :) Do this:

sudo find  /usr/lib/python2.5/site-packages/django -type d -exec chmod go+rx {} \;
sudo find  /usr/lib/python2.5/site-packages/django -type f -exec chmod go+r {} \;
查看更多
叼着烟拽天下
7楼-- · 2020-01-24 11:58

To tack on to what lichenbo said... If you are using Windows, then Don't run with 'django-admin.py'...

I'm running inside a virtual environment, so the path and command to create a new project looks like:

(DjangoEnv)  C:\users\timreilly\Envs\django\Scripts\django-admin.exe startproject myproject

DjangoEnv is the name of my virtual environment.

查看更多
登录 后发表回答