11

I'm learning django and I did successfully start a site on Windows XP by following the tutorial.

However, on Windows 7 when I issued:

django-admin.py startproject mysite

python.exe was started and a window appeared to ask me to choose either python.exe or other program to open a file....

Did I do anything wrong or there are more tricks for windows 7?

0

12 Answers 12

14

That's already been reported to the django, see http://bugs.python.org/issue7936 And these's an solution: open regedit and find python.exe like this "C:\Python26\python.exe" "%1" change it to "C:\Python26\python.exe" "%1" %*

4
  • 3
    For instance, under HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command Dec 27, 2010 at 4:39
  • I had the same problem as the OP, this fixed it for me. Thanks. Mar 24, 2011 at 9:59
  • 2
    This worked for me, I had to change two register keys: HKEY_CLASSES_ROOT\py_auto_file\shell\open\command HKEY_CURRENT_USER\Software\Classes\Applications\python.exe\shell\open\command
    – Sam
    Jan 9, 2012 at 19:22
  • Is there a solution for Python27? I've tried looking for this and I can't find it where you say it should be located..
    – Gerico
    Apr 4, 2014 at 18:44
13

This is what worked for me: I already had c:\python27 and c:\python27\Scripts in PATH.

  1. Copy django-admin.py and django-admin-script.py from c:\python27\Scripts to your desired folder
  2. with cmd go to that folder and run > django-admin startproject mysite

Note that if I doesn't type python windows just opens the django-admin.py in editor.

9

I had the same error when I ran django-admin.py on the command prompt. I couldn't create a projects.

I tried to run Regedit by using Find to Search python.exe and then adding %% but it was not sufficient.
I then added the necessary Path to the System PATH as shown below.

Open:
Control Panel -> System -> Advanced -> Environment Variables -> PATH.

Add to the PATH:

C:\Python27\python.exe;C:\Python27\Scripts;C:\Python27\Lib\site-packages\django\bin

It Work! Now I can Create Django Projects and applications Using Command on Windows 7.

2

In latest django(1.11.7 for now) , simple django-admin would work, instead of django-admin.py .

1
  • In Django 2+ confirmed to work as well. In cmd.exe simply using 'django-admin ...' will work. pip3 install django will install a 'django-admin.exe' script in the 'Scripts' folder of your activate python environment. Mar 12, 2018 at 12:50
1

I had the same problem i followed django-admin.py startproject mysite not working well on windows 7 and found that the python files still associated with my text editor. Changing the necessary registry keys fix the issue.

1

I also had the same problem but don't worry its simple to solve this problem, just add "C:\Users\Nik's\myenv\Scripts" to the enviroment veriables and its done. The address may be differnt in your pc as it depends where you install it.

0

Change the first line of django-admin.py #!/usr/bin/env python to for example #!D:\Program Files\Python\python.exe (Where you install your python.exe,that's my directory); it works.

0

The solution is simple in Windows:

1-Go to C: \ Python34 \ Scripts

2-Right click on django-admin.py

3-Select open with

4-Select default program

5-Select Laucher Python for Windows (Console)

6- Run the command in CMD Windows python django-admin.py startproject mysite

0

In Windows 8.1, I faced the same problem. In my case when I tried to create my project, it would open the contents of the page in Internet Explorer window rather than creating the project folder. I became curious of what exactly was this django-manage.py. After searching, I got to django-admin.py file in the path C:\Python34\Scripts and I right clicked on it chose to open with default program of Launcher Python for Windows(Console).

Again I got back to the CMD and in my project directory I entered: django-admin.py startproject mysite

And worked just fine.!!!

0

I have faced the same issue and when I ran the Python installer again and clicked on the repair option, it magically fixed everything for me. Now, I can run django-admin straight from CMD.

0
  1. first of all make sure that python/Scripts is in your path
  2. run "django-admin startproject mysite" instead of "django-admin.py startproject mysite"
0

I get the same problem for Windows 10. Here is how I resolve it:

  1. I run the terminal CMD with administrator right. How to do that ? Right click on the terminal and click on Run as administrator.
  2. I install django by doing: python -m pip install django. You can check that django is really installed by doing: python -m pip freeze. If you see django in the list, then django is installed.
  3. Finally, I create my django project by doing: django-admin startproject project-name.

NB: For step 3, you don't need the terminal with administrator right.

Not the answer you're looking for? Browse other questions tagged or ask your own question.