2

Please help me find the cause of this problem with my Django installation on Windows.

C:\Djangoprojects>django-admin.py startproject mydjangoblog
Traceback (most recent call last):
  File "C:\Python27\Scripts\django-admin.py", line 4, in <module>
  import pkg_resources
  File "build\bdist.win-amd64\egg\pkg_resources.py", line 3007, in <module>
  File "build\bdist.win-amd64\egg\pkg_resources.py", line 728, in require
  File "build\bdist.win-amd64\egg\pkg_resources.py", line 626, in resolve
  pkg_resources.DistributionNotFound: django==1.5.1

I just installed Django 1.5.1 and I remember I had the 1.4.3 before removing it. When I try to create a project, the above error is shown.

After a few adjustments - which included adding the whole directory of Python27\Lib\site-packages\django\bin to the path variable, this is the error I now get when I try to create a project:

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

The question am now asking myself is this: Where should I put the django folder? In its own place or within python27?

I can import Django through the Python Interactive shell without a problem. I have also added django-admin.py to the system path variable just in case.

Thanks in advance.

Henrik Andersson
  • 37,809
  • 15
  • 88
  • 86
Eenvincible
  • 5,725
  • 2
  • 25
  • 42

5 Answers5

2

I finally was able to fix this problem. Here is what I did after spending some time on Stackoverflow:

  • Leave everything the way it was installed by easy_install when I installed it.
  • Make sure that there is one django installation.
  • Make sure the django-admin.py is inside Python27\Scripts
  • To create a django project do: on the command line:

  • python C:\Python27\Scripts\django-admin.py startproject demosite instead of just: django-admin.py startproject demosite.

  • The easiest way to make creating projects easier, you can create a batch file called startproject.bat and save it inside Python27\Scripts\ folder. Inside that file, add the following: python C:\Python27\Scripts\django-admin.py startproject %1
  • Now, on your command line,you will be able to simply say : startproject.bat demosite

This worked out for me at last and I am happy to say this problem has been solved! I hope this was helpful to others as well.

I want to thank everyone who took their time to answer this question. I could have voted up your answer but I don't have enough points, but until then, I appreciate it.

Eenvincible
  • 5,725
  • 2
  • 25
  • 42
0

There is an easy way is to install pip, the python package manager on Windows and install Django using pip. Pip will handle the environment variables and paths for you.

pip install django --upgrade
Community
  • 1
  • 1
zs2020
  • 52,221
  • 27
  • 148
  • 209
  • I used easy_install to install Django 1.5.1. I had the previous version when I installed the newer one. Should I move the django itself to a different location? and if so, where? Thanks – Eenvincible Aug 02 '13 at 03:48
0

you can easily uninstall django by just deleting the folder C:\Python27\Lib\site-packages\django

new installation

that is it.

now try django-admin.py startproject mydjangoblog

suhailvs
  • 14,937
  • 8
  • 78
  • 88
0

I suggest you to use virtualenv to maintain a clean python environment.

  1. install virtualenv, and add it to your env-path

  2. run cmd mkvirtualenv django to create the env for your django project

  3. run pip.exe install to install needed libraries.

lethe3000
  • 123
  • 1
  • 4
0

Above issue take place due multiple Django package installed on system. To overcome issue just remove all django package and reinstall latest django package on pc.

on linux

  • $ sudo pip uninstall Django == version
  • $ sudo pip install Django