Eenvincible
Eenvincible

Reputation: 5626

I cannot create a project because of Django installation on Windows

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.

Upvotes: 2

Views: 2301

Answers (5)

Satish Chauhan
Satish Chauhan

Reputation: 116

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

Upvotes: 0

Eenvincible
Eenvincible

Reputation: 5626

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.

Upvotes: 2

lethe3000
lethe3000

Reputation: 153

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.

Upvotes: 0

suhailvs
suhailvs

Reputation: 21740

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

Upvotes: 0

zs2020
zs2020

Reputation: 54543

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

Upvotes: 0

Related Questions