There is no module named django.core

I upgraded to the latest version of Django 1.0.2 after uninstalling my old version of Django. But now when I run django-admin.py, I get the following error. How can i solve 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 
+65
python django
Nov 23 '08 at 14:09
source share
25 answers

You have to make sure django is in your PYTHONPATH.

To check, just do import django from the python shell. There should be no way out:

 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 through setuptools ( easy_install or using setup.py included in django), then check site-packages if the .pth file ( easy-install.pth , django.pth , ...) specify the correct folder.

E.I.V ..

+36
Nov 28 '08 at 8:40
source share

I have the same problem for Windows and it looks like I found the problem. I have both 2.7 and 3.x installed. This seems to be related to the associated .py program:

At the command line:

assoc.py

and the result:

.py = Python.File

which means .py is related to Python.File

then I tried this:

ftype Python.File

I got:

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

which means that .py on the command line is related to my Python 3.2 installation - and therefore I cannot just type "django-admin.py blah blah" to use django.

ALL you have to do is change the association:

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

then everything is all right!

+39
Apr 09 '12 at 7:13
source share

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

 python c:\python25\scripts\django-admin.py startproject mysite 
+21
Jan 31 '10 at 16:08
source share

Today I ran into this problem, it turned out that I had C: \ Python26 in my path, and the .py files were associated with Python 3.1. Restoring the correct version of Python using programs and functions or by running .msi will fix the associations.

+16
Feb 28 '10 at 21:21
source share

This was the PYTHONPATH environment variable problem for me, like the others mentioned above, but no one showed how to set it up for people who could use the extra instruction.

Linux (bash)

I set this variable to my bashrc file in my home folder (.bashrc is the file for me, since my shell is / bin / bash).

 vim ~/.bashrc export PYTHONPATH=/usr/local/python-2.7.2/lib/python2.7/site-packages:$PYTHONPATH source ~/.bashrc 

The path should be wherever the source of django is. Mine is located at / usr / local / python -2.7.2 / lib / python2.7 / site-packages / django, so I just specified / usr / local / python -2.7.2 / lib / python2.7 / site- packages without django part.

OSX

On OSX, the path is /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages , and you can add it to /etc/profile :

 sudo echo "PYTHONPATH=/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages:$PYTHONPATH" >> /etc/profile source /etc/profile 
+10
Nov 18 '11 at 17:07
source share

I'm sure this is due to something wrong in my setup, but I have the same problem and it works correctly if I call it that

 c:\somedir>python c:\Python26\scripts\django-admin.py startproject mysite 
+8
Jan 17 '10 at 15:21
source share

If you are using Windows, then do not start it using 'django-admin.py', as this will cause your external python.exe to execute and will not be able to read in django inside the virtual environment. Try "python django-admin.py" to use your python.exe inside your environment.

+7
Mar 02 '13 at 10:16
source share

This worked for me with djangostack bits:

 python apps\django\django\bin\django-admin.py startproject mysite 
+5
Mar 08 '10 at 0:30
source share

I had the same problem in windows xp. The reason is that I installed several versions of python (2.6.3.2) .windows PATH is correctly installed on python26, but the .py file is associated with python32. I want the .py file to be associated with python26. To solve this problem, an easy way is to right-click on * .py (for example, django-admin.py), select "open from" β†’ "select program ... "β†’" Browse ... "(select c: \ python26 \ python.ext) β†’" Ok ". Then we can run django-admin.py in cmd without the need for the expansion prefix "c: \ python26 \ lib \ site-packages \ django \ bin".

+2
Mar 01 2018-11-11T00:
source share

I had the same problem and recalled that I installed iPython yesterday afternoon. I uninstalled iPython and the problem went away. By the way, I work with virtualenv. I installed iPython in the system-wide directory of package sites, so I just reinstalled iPython inside every virtual file I use. After installing iPython yesterday, I noticed a warning (starting with version 0.13 of iPython) that I found that I was using virtualenv, and that if I had any problems, I had to install iPyton inside each virtual file.

+2
Oct 03 '12 at 20:30
source share

If your path variables are correct and from the python shell you can do: from the django.core import control, make sure you include "python" before "django-admin.py" as such: python django-admin. py startproject thelittlethings

+1
May 27 '10 at 16:49
source share

The simplest solution, although not the most elegant, is to copy django-admin.py from the Scripts folder. The Scripts folder will be found under your Python installation. On my computer, it is located in C: \ Python26 \ Scripts. Then paste django-admin.py in the folder from which you are trying to run the file. It is true that using the system path will give flexibility. This is a special decision if you are in a hurry. Then enter for example python django-admin.py startproject fluffyteaspoons and you will create a fluffyteaspoons project

+1
Mar 10 '11 at 8:20
source share

In my case, I'm on OS X Lion, and I installed Python with homebrew. I got 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 incorrect, as it indicated the installation of the python system:

 #!/usr/bin/python 

I just changed it to indicate a home installation:

 #!/usr/local/bin/python 

And it worked :)

+1
Dec 15 '11 at 23:47
source share

I know this is an old question, but I had the same problem, in my case it is due to the fact that I use virtualenv with django, but the .py file extensions on Windows are related to the main Python installation, so running django-admin. py is implemented directly from the command line, forcing it to start with the main Python installation without installing django.

So, since I don't know if there is any hash pound equivalent on Windows, I worked on this by running python followed by the full path django-admin.py, or you can also change the virtualenv script package to change file associations and change them back when you deactivate it (although I'm not sure how to do this, since I'm not very familiar with the script package).

Hope this helps,

+1
Mar 23 2018-12-12T00:
source share

It worked on Mac OS X

In python terminal run In python: import sys print sys.path

Find the path of the site packages. I found this in the sys.path output: '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages'

exit python. Find where your current site packages are. Mine were in / Library / Python / 2.6 / site-packages

Now be careful: check the contents of the package sites to make sure it is empty. That is, the directory /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages must be empty or contain a readme file. If so, delete this directory, because now you are going to create a symbolic link.

ln -s / Library / Python / 2.6 / site-packages / Library / Frameworks / Python.framework / Versions / 2.7 / lib / python2.7 / site-packages

If you do not delete the folder, you will place a symbolic link in the folder.

Other options are to add the path to sys.path. I chose a symbolic route because I have several versions of python, I don’t want several versions of Django and just want to point to a known working copy.

+1
Sep 24
source share

I just got the same ImportError on Windows Vista that has Python 2.7 and 3.2 installed and using virualenv with Python 2.7 and Django 1.4.3.

I changed the association of .py files in Explorer from 3.2 to 2.7. Right-click the .py file and change the settings. I still have ImportError.

I ran cmd.exe as an administrator and copied the previous ftype stuff. After the error, note that double quotes are not copied correctly from the browser to cmd. Rewrote the command in cmd, but I still have ImportError.

In the root of the activated virtual environment, I explicitly gave the python command and the path to django-admin.py from there. (env_p27) C:\Users\Gemmu\env_p27>python .\Scripts\django-admin.py startproject mysite

It worked.

Thanks for helping everyone.

+1
Jan 27 '13 at 13:22
source share

This happened to me because I was running pip as sudo , while my virtualenv was configured to not import external site packages, so Django was installed for the root user, but not in virtualenv, although I activated virtualenv when I ran sudo.

The solution is to switch to root, activate venv, and then install pip.

+1
Aug 01 '13 at 10:29 on
source share

As usual, the install script failed to set read / execute permissions in the world :) 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 {} \; 
0
Jan 28 '10 at 12:29
source share

Thanks for reporting the question and answers. I have two versions of Python, but root points to the version of / usr / bin, and I wanted to use the version of Python version 2.7 in the / usr / local / bin directory. After repairing / reinstalling Django and mysqldb, everything is fine and I am not getting an error.

0
Sep 15 '10 at 17:59
source share

A small quick fix is ​​to simply create a symbolic link ln -s $SOMEWHERE/lib/python2.6/site-packages/django/ ./django

0
Jan 01 '10 at 11:24
source share

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

 PYTHONHOME\Lib\site-packages\django 

Of course you should change PYTHONHOME to your Python installation directory, as I explained.

Please note that you can edit django.pth to include any directory that you want to include in PYTHONPATH . In fact, you can name this file as you wish, path.pth , for example, if you want it to be more general and include several directory paths.

0
Jan 18 2018-11-11T00: 00Z
source share

Okay .. I'm doing something radical. I am unistall python and I am removing from the environment Variables/PATH this: ;C:\Python26\Scripts;C:\Python26. And his job ... I used to have your problem.

0
Apr 25 '12 at 8:11
source share

I realized that this happened because I did not run python setup.py install . This is an environment setting.

0
Dec 27 '13 at 8:01
source share

To understand what lichenbo said ... If you are using Windows, then do not start it with 'django-admin.py' ..

I run inside a virtual environment, so the path and command to create a new project are as follows:

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

DjangoEnv is the name of my virtual environment.

0
Sep 01 '15 at 22:02
source share

After reading a lot, I found a solution that works for me.

I have

  django version 1.9.2 
  • Set the entire system variable in the "path". Do not duplicate the copy in the user variable, as well as in PYTHONPATH. enter image description here

  • Then set the value to regedit

enter image description here

  1. made virtualenv in the desired folder with the command

    virtualenv venv

  2. And finally in cmd

team

 django-admin.py startproject MySite ***and not this*** python django-admin.py startproject MySite 

in the root folder "VENV"

And he worked

0
Feb 08 '16 at 6:35
source share



All Articles