No Module named django.core

Viewed 101053

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
25 Answers

I have the same problem on Windows and it seems I've found the problem. I have both 2.7 and 3.x installed. It seems it has something to do with the associate program of .py:

In commandline type:

assoc .py

and the result is:

.py=Python.File

which means .py is associated with Python.File

then I tried this:

ftype Python.File

I got:

Python.File="C:\Python32\python.exe" "%1" %*

which means in commandline .py is associated with my Python 3.2 installation -- and that's why I can't just type "django-admin.py blah blah" to use django.

ALL you need to do is change the association:

ftype Python.File="C:\Python27\python.exe" "%1" %*

then everythong's okay!

You must make sure that django is in your PYTHONPATH.

To test, just do a import django from a python shell. There should be no output:

ActivePython 2.5.1.1 (ActiveState Software Inc.) based on
Python 2.5.1 (r251:54863, May  1 2007, 17:47:05) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>>

If you installed django via setuptools (easy_install, or with the setup.py included with django), then check in your site-packages if the .pth file (easy-install.pth, django.pth, ...) point to the correct folder.

HIH.

You can get around this problem by providing the full path to your django-admin.py file

python c:\python25\scripts\django-admin.py startproject mysite

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.

I'm sure it's related to something incorrect in my setup, but it works properly if I do this:

python c:\Python26\scripts\django-admin.py startproject mysite

This worked for me with bitnami djangostack:

python apps\django\django\bin\django-admin.py startproject mysite

I know that this is an old question, but I just had the same problem, in my case, it was because the I am using virtualenv with django, but .py file extensions in Windows are associated with the main Python installation, so running the django-admin.py are directly from the command prompt causes it run with the main Python installation without django installed.

So, since i dont know if there is any hash pound equivalent in Windows, I worked around this by running python followed by the full path of the django-admin.py, or you can also modify the virtualenv batch script to change the file associations and change it back when you deactivate it (although I am not sure how to do it, as I am not really familiar with batch script).

Hope this helps,

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 {} \;

Small quick fix is just to create symlink ln -s $SOMEWHERE/lib/python2.6/site-packages/django/ ./django

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.

Related