[ACCEPTED]-No Module named django.core-django
I have the same problem on Windows and it 13 seems I've found the problem. I have both 12 2.7 and 3.x installed. It seems it has something 11 to do with the associate program of .py:
In 10 commandline type:
assoc .py
and the result 9 is:
.py=Python.File
which means .py is associated 8 with Python.File
then I tried this:
ftype 7 Python.File
I got:
Python.File="C:\Python32\python.exe" "%1" %*
which 6 means in commandline .py is associated with 5 my Python 3.2 installation -- and that's 4 why I can't just type "django-admin.py blah 3 blah" to use django.
ALL you need to do is 2 change the association:
ftype Python.File="C:\Python27\python.exe" "%1" %*
then 1 everythong's okay!
You must make sure that django is in your 5 PYTHONPATH.
To test, just do a import django
from a python 4 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 3 installed django via setuptools
(easy_install
, or with the setup.py
included 2 with django), then check in your site-packages
if the 1 .pth
file (easy-install.pth
, django.pth
, ...) point to the correct folder.
HIH.
You can get around this problem by providing 1 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 5 out that I had C:\Python26 in my path and 4 .py files were associated to Python 3.1. Repairing 3 the proper version of Python, either through 2 Programs and Features or by running the 1 .msi, will fix the associations.
It was a PYTHONPATH environment variable 11 issue for me, as others mentioned above, but 10 noone has really shown how to set it for 9 people that could use the extra instruction.
Linux (bash)
I 8 set this variable in my bashrc file in my 7 home folder (.bashrc is the file for me 6 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 5 be wherever your django source is. Mine 4 is located at /usr/local/python-2.7.2/lib/python2.7/site-packages/django, so 3 I just specified /usr/local/python-2.7.2/lib/python2.7/site-packages 2 without the django portion.
OSX
On OSX the path 1 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
I'm sure it's related to something incorrect 2 in my setup, but I am having the same problem, and 1 it works properly if I call it thusly
c:\somedir>python c:\Python26\scripts\django-admin.py startproject mysite
If you are using Windows, then Don't run 5 with 'django-admin.py', since this will 4 call your outer python.exe to execute and 3 it cannot read into the django inside the 2 virtual environemnt. Try 'python django-admin.py' to 1 use your python.exe inside your environment.
This worked for me with bitnami djangostack:
python apps\django\django\bin\django-admin.py startproject mysite
0
I had the same problem in windows xp. The 10 reason was i installed multiple python versions(2.6,3.2).windows's 9 PATH is set correctly to python26, but the 8 .py file is associated with python32. I 7 want the .py file is associated with python26.To 6 solve it, the easit way is to right click 5 the *.py(such as django-admin.py),choose 4 "open with"->"choose program..."->"Browse..." (select 3 c:\python26\python.ext)->"Ok". Then we can 2 run django-admin.py in the cmd without the 1 need for the expatiatory prefix "c:\python26\lib\site-packages\django\bin".
I know that this is an old question, but 17 I just had the same problem, in my case, it 16 was because the I am using virtualenv with 15 django, but .py file extensions in Windows 14 are associated with the main Python installation, so 13 running the django-admin.py are directly 12 from the command prompt causes it run with 11 the main Python installation without django 10 installed.
So, since i dont know if there 9 is any hash pound equivalent in Windows, I 8 worked around this by running python followed 7 by the full path of the django-admin.py, or 6 you can also modify the virtualenv batch 5 script to change the file associations and 4 change it back when you deactivate it (although 3 I am not sure how to do it, as I am not 2 really familiar with batch script).
Hope 1 this helps,
I had the same problem and recalled that 12 I had installed iPython the previous afternoon. I 11 uninstalled iPython and the problem went 10 away. Incidentally, I am working with virtualenv. I 9 had installed iPython in the system-wide 8 site-packages directory, so I just re-installed 7 iPython inside each virtualenv that I am 6 using. After installing iPython yesterday 5 I had noticed a warning message (from version 4 0.13 of iPython) that it had detected that 3 I was using virtualenv and that if I ran 2 into any trouble I should install iPyton 1 inside each virtualenv.
If your path variables are correct and from 5 the python shell you can do: from django.core 4 import management , make sure you're including 3 "python" before "django-admin.py" as such: python 2 django-admin.py startproject thelittlethings 1
The simplest solution though not the most 12 elegant is to copy the django-admin.py from 11 the Scripts folder. The Scripts folder will 10 be found under your Python installation 9 . On my computer it is in C:\Python26\Scripts. Then 8 paste the django-admin.py into the folder 7 you are trying to run the file from. It 6 is true that the use of the System path 5 will give flexibility. This is a particular 4 solution if you are in a hurry. Then type 3 for instance python django-admin.py startproject 2 fluffyteaspoons and you will create the 1 project fluffyteaspoons
In my case, I'm on OS X Lion and I've installed 7 Python with homebrew I was getting the same error, but 6 none of the solutions posted here helped 5 me. In my case I just had to edit the script:
vim /usr/local/share/python/django-admin.py
And 4 I noticed that the first line was wrong, as 3 it was pointing to the system's python installation:
#!/usr/bin/python
I 2 just modified it to point to homebrew's 1 installation:
#!/usr/local/bin/python
And it worked :)
This worked on Mac OS X
In the terminal run 19 python In python: import sys print sys.path
Look 18 for the site packages path. I found this 17 in the output of sys.path: '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages'
exit 16 python. Find where your current site-packages 15 are. Mine were at /Library/Python/2.6/site-packages 14
Now be careful: Check the content of site-packages 13 to be sure it is empty. That is, directory 12 /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages 11 should be empty, or just contain a readme 10 file. If it is, delete that directory, because 9 you are now about to make a symlink.
ln -s 8 /Library/Python/2.6/site-packages /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
If 7 you don't delete the folder you will put 6 the symlink in the folder.
Other options 5 are to add the path to the sys.path. I elected 4 the symlink route because I have a couple 3 of versions of python, I don't want several 2 versions of Django, and just wanted to point 1 to the known working copy.
I just got the same ImportError in Windows 14 Vista having Python 2.7 and 3.2 installed 13 and using virualenv with Python 2.7 and 12 Django 1.4.3.
I changed the file association 11 of .py files in Explorer from 3.2 to 2.7. Rightclicking 10 a .py file and changing settings. I still 9 got the ImportError.
I ran cmd.exe
as an administrator 8 and copypasted the earlier ftype
stuff. After 7 an error, noted that double quotes don't 6 get copied correctly from browser to cmd. Rewrote 5 the command in cmd, but I still got the 4 ImportError.
In root of the actived virtual 3 environment, I explicitly gave the python
command 2 and the path to django-admin.py from there.
(env_p27) C:\Users\Gemmu\env_p27>python .\Scripts\django-admin.py startproject mysite
That 1 worked.
Thanks for all the help for everyone.
This happened to me because I ran pip
as sudo
while 6 my virtualenv is setup to not import outside 5 site packages so Django was installed for 4 the root user but not in the virtualenv, even 3 though I had virtualenv activated when I 2 ran sudo.
Solution switch to root, activate 1 venv then do pip install.
To tack on to what lichenbo said... If you are using 5 Windows, then Don't run with 'django-admin.py'...
I'm 4 running inside a virtual environment, so 3 the path and command to create a new project 2 looks like:
(DjangoEnv) C:\users\timreilly\Envs\django\Scripts\django-admin.exe startproject myproject
DjangoEnv is the name of my 1 virtual environment.
As usual, an install script failed to set 1 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 {} \;
Thanks for posting the question and answers. I 6 have two versions of Python installed, but 5 root was pointing to the /usr/bin version, and 4 I wanted to use the 2.7 version of Python 3 in /usr/local/bin. After rebuilding/reinstalling 2 Django and mysqldb, all is well and I'm 1 not getting the error.
Small quick fix is just to create symlink 1 ln -s $SOMEWHERE/lib/python2.6/site-packages/django/ ./django
I had the same problem, it was clear that 13 I had a PYTHONPATH
configuration issue. The solution 12 is quite simple, just create a file with 11 this name django.pth
in your PYTHONHOME\Lib\site-packages
directory where PYTHONHOME
is 10 the directory where Python is installed 9 (mine is: C:\Python27). Add the following 8 line to the django.pth
file:
PYTHONHOME\Lib\site-packages\django
Of course you have to 7 change PYTHONHOME
to your Python's installation directory 6 as I explained.
Note that you can edit the 5 django.pth
to include any directory that you want 4 to be included in the PYTHONPATH
. Actually, you can 3 name that file as you wish, path.pth
for example 2 if you want it to be more general and to 1 include several directory paths.
Well.. I do something radical. I unistall 2 python and I delete from Environment Variables/PATH this: ;C:\Python26\Scripts;C:\Python26.
And 1 Its work...
I had your problem before.
I realized this happen because I didn't 1 run python setup.py install
. That setup the environment.
After reading a lot I found a solution that 7 works for me.
I have
django version 1.9.2
Set all system variable 6 in "path".No duplicate copy in 5 user variable nor in the PYTHONPATH .
Then 4 set Value in regedit
made a virtualenv in 3 desired folder by command
virtualenv VENV
And 2 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 1 "VENV"
And It worked
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.