No Module named django.core

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


Asked by: Connie279 | Posted: 05-10-2021






Answer 1

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!

Answered by: Kate494 | Posted: 06-11-2021



Answer 2

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.

Answered by: Blake768 | Posted: 06-11-2021



Answer 3

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

Answered by: Elise992 | Posted: 06-11-2021



Answer 4

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.

Answered by: Steven199 | Posted: 06-11-2021



Answer 5

It was a PYTHONPATH environment variable issue for me, as others mentioned above, but noone has really shown how to set it for people that could use the extra instruction.

Linux (bash)

I set this variable in 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 your django source 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 the django portion.

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

Answered by: Ryan535 | Posted: 06-11-2021



Answer 6

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

Answered by: Hailey449 | Posted: 06-11-2021



Answer 7

If you are using Windows, then Don't run with 'django-admin.py', since this will call your outer python.exe to execute and it cannot read into the django inside the virtual environemnt. Try 'python django-admin.py' to use your python.exe inside your environment.

Answered by: Luke686 | Posted: 06-11-2021



Answer 8

This worked for me with bitnami djangostack:

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

Answered by: Leonardo100 | Posted: 06-11-2021



Answer 9

I had the same problem in windows xp. The reason was i installed multiple python versions(2.6,3.2).windows's PATH is set correctly to python26, but the .py file is associated with python32. I want the .py file is associated with python26.To solve it, the easit way is to right click the *.py(such as django-admin.py),choose "open with"->"choose program..."->"Browse..." (select c:\python26\python.ext)->"Ok". Then we can run django-admin.py in the cmd without the need for the expatiatory prefix "c:\python26\lib\site-packages\django\bin".

Answered by: Dainton535 | Posted: 06-11-2021



Answer 10

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,

Answered by: Kelvin473 | Posted: 06-11-2021



Answer 11

I had the same problem and recalled that I had installed iPython the previous afternoon. I uninstalled iPython and the problem went away. Incidentally, I am working with virtualenv. I had installed iPython in the system-wide site-packages directory, so I just re-installed iPython inside each virtualenv that I am using. After installing iPython yesterday I had noticed a warning message (from version 0.13 of iPython) that it had detected that I was using virtualenv and that if I ran into any trouble I should install iPyton inside each virtualenv.

Answered by: Maddie964 | Posted: 06-11-2021



Answer 12

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

Answered by: Grace497 | Posted: 06-11-2021



Answer 13

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

Answered by: Tara601 | Posted: 06-11-2021



Answer 14

This worked on Mac OS X

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

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

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

Now be careful: Check the content of site-packages to be sure it is empty. That is, directory /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages should be empty, or just contain a readme file. If it is, delete that directory, because you are now about to make a symlink.

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

If you don't delete the folder you will put the symlink in the folder.

Other options are to add the path to the sys.path. I elected the symlink route because I have a couple of versions of python, I don't want several versions of Django, and just wanted to point to the known working copy.

Answered by: Blake734 | Posted: 06-11-2021



Answer 15

I just got the same ImportError in Windows Vista having Python 2.7 and 3.2 installed and using virualenv with Python 2.7 and Django 1.4.3.

I changed the file association of .py files in Explorer from 3.2 to 2.7. Rightclicking a .py file and changing settings. I still got the ImportError.

I ran cmd.exe as an administrator and copypasted the earlier ftype stuff. After an error, noted that double quotes don't get copied correctly from browser to cmd. Rewrote the command in cmd, but I still got the ImportError.

In root of the actived 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

That worked.

Thanks for all the help for everyone.

Answered by: Rafael270 | Posted: 06-11-2021



Answer 16

This happened to me because I ran pip as sudo while my virtualenv is setup to not import outside site packages so Django was installed for the root user but not in the virtualenv, even though I had virtualenv activated when I ran sudo.

Solution switch to root, activate venv then do pip install.

Answered by: Oliver415 | Posted: 06-11-2021



Answer 17

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.

Answered by: Sienna973 | Posted: 06-11-2021



Answer 18

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 :)

Answered by: Wilson153 | Posted: 06-11-2021



Answer 19

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

Answered by: Kellan953 | Posted: 06-11-2021



Answer 20

Thanks for posting the question and answers. I have two versions of Python installed, but root was pointing to the /usr/bin version, and I wanted to use the 2.7 version of Python in /usr/local/bin. After rebuilding/reinstalling Django and mysqldb, all is well and I'm not getting the error.

Answered by: Clark708 | Posted: 06-11-2021



Answer 21

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

Answered by: Abigail342 | Posted: 06-11-2021



Answer 22

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.

Answered by: Grace350 | Posted: 06-11-2021



Answer 23

Well.. I do something radical. I unistall python and I delete from Environment Variables/PATH this: ;C:\Python26\Scripts;C:\Python26. And Its work... I had your problem before.

Answered by: Thomas203 | Posted: 06-11-2021



Answer 24

I realized this happen because I didn't run python setup.py install. That setup the environment.

Answered by: Edgar829 | Posted: 06-11-2021



Answer 25

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

I have

 django version 1.9.2
  1. Set all system variable in "path".No duplicate copy in user variable nor in the PYTHONPATH . enter image description here

  2. Then set Value in regedit

enter image description here

  1. made a virtualenv in desired folder by command

    virtualenv VENV

  2. And finally in cmd

used command

django-admin.py startproject MySite

***and not this***

python django-admin.py startproject MySite 

at the root folder of the "VENV"

And It worked

Answered by: Oliver109 | Posted: 06-11-2021



Similar questions

python - No module names django.core, but I can import django from the shell

When I run django in a virtual environment, I get No module named 'django.core': (proj)[jenia@li app]$ python manage.py runserver Traceback (most recent call last): File "manage.py", line 8, in &lt;module&gt; from django.core.management import execute_from_command_line ImportError: No module named 'django.core' However, when I run the Python interpreter, ...


python - No module named django.core error

EDIT #2: Solved! 7 hours spent because of a default read-only permission. See answer below! Windows 8 machine, Django 1.6.5, Python 2.7.8 So I set Django up earlier on a VPN (trying to learn to code from China is tough) and everything worked well. However, this time I tried it, I got this error: ImportError: No module named django.core Here's a picture of it in full:


python - Why is django giving error: no module named django.core?

I get the error in question when I attempt to create a project. I followed the instructions found at how to install python an django in windows vista.


python - No module names django.core, but I can import django from the shell

When I run django in a virtual environment, I get No module named 'django.core': (proj)[jenia@li app]$ python manage.py runserver Traceback (most recent call last): File "manage.py", line 8, in &lt;module&gt; from django.core.management import execute_from_command_line ImportError: No module named 'django.core' However, when I run the Python interpreter, ...


python - No module named django.core error

EDIT #2: Solved! 7 hours spent because of a default read-only permission. See answer below! Windows 8 machine, Django 1.6.5, Python 2.7.8 So I set Django up earlier on a VPN (trying to learn to code from China is tough) and everything worked well. However, this time I tried it, I got this error: ImportError: No module named django.core Here's a picture of it in full:


python - Why is django giving error: no module named django.core?

I get the error in question when I attempt to create a project. I followed the instructions found at how to install python an django in windows vista.


Python + Django + Virtualenv importing django.core failed

I'm using Python 2.7.3 on Windows 7. I've set PATH as a C:\python27 which is a original python binary path. First, I made a new Virtualenv named "django" without any options, virtualenv django Second, activated Virtualenv, c:\workspace\py-envs\django\Scripts\activate Third, installed Django by using pip, pip install dja...


python - No module names django.core, but I can import django from the shell

When I run django in a virtual environment, I get No module named 'django.core': (proj)[jenia@li app]$ python manage.py runserver Traceback (most recent call last): File "manage.py", line 8, in &lt;module&gt; from django.core.management import execute_from_command_line ImportError: No module named 'django.core' However, when I run the Python interpreter, ...


python - No module named django.core error

EDIT #2: Solved! 7 hours spent because of a default read-only permission. See answer below! Windows 8 machine, Django 1.6.5, Python 2.7.8 So I set Django up earlier on a VPN (trying to learn to code from China is tough) and everything worked well. However, this time I tried it, I got this error: ImportError: No module named django.core Here's a picture of it in full:


python - There is no module django.core when starting a project

Hi am struggling for over 12 hrs with python 2.7, I was working with python 3.7 so i decided to change to 2.7 for a certain reason ,so i uninstalled 3.7 and installed 2.7 But after activating the virtual environment cant start a project with this error. I went through all the procedures here but i could not fix the problem. The strange th...


python - when ever i am trying to start a project after i have installed django, execution displays No Module Found Error :django module or django.core

(.env) C:\Users\shara\Desktop\testfolder\_djhole&gt;pip install Django (executed) (.env) C:\Users\shara\Desktop\testfolder\_djhole&gt;django-admin start project my site (No Module Found Error) I have repeated this process for a long time. Cannot start working on Django so far due to this: ModuleNotFoundError: No module named 'django.core'; 'Django' is not a package






Still can't find your answer? Check out these communities...



PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python



top