Can't open file 'django-admin.py': [Er

2020-02-05 03:17发布

I'm using Python 2.7, Django 1.2.5 and on Windows 7.

I am not sure what I've done. I used to be able to create Django projects like

python django-admin.py startproject test

Now however I get this error.

Can't open file 'django-admin.py':
[Errno 2] No such file or directory

I can type the following which works.

python C:\Python27\Scripts\django-admin.py startproject test

How can I have it the way it used to be? Not having the type the full path to the django-admin.py file.

Things I've already tried:

I uninstalled Python and manually removed the values from the PATH variable in Windows. Reinstalled Python. Deleted Django and reinstalled it too.

I've added C:\Python27\Scripts to my PATH and PYTHONPATH variable under Environmental Variables in Windows.

Any suggestions?

My PATH variable contains

C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\ActiveState Komodo Edit 6\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\django-apps;F:\My_Projects;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Mercurial\bin;C:\Python27;C:\Python27\Scripts

PYTHONPATH has

C:\Python27;C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk;C:\Python27\Scripts;C:\django-apps;f:\my_projects

12条回答
爱情/是我丢掉的垃圾
2楼-- · 2020-02-05 04:02

If C:\Python27\Scripts is in your Path, just type in:

django-admin.py startproject proj

There should be a file association with .py and try to execute. If you prefix with python the next command is a file path.

I've never been able to do python django-admin.py -- I get the same error you describe.

Make sure python is associated with .py. You can check via file properties (opens with...) or typing assoc .py in cmd.

查看更多
小情绪 Triste *
3楼-- · 2020-02-05 04:04

After I installed an IDE, I had a similar (if not the same) problem. Sure enough, the .py "Open With" setting had been changed, and changing it back to the Python Launcher for Windows did the trick.

查看更多
该账号已被封号
4楼-- · 2020-02-05 04:05

I had this same problem with slightly newer versions of Python 2.7.x and Django - and it is not the PATH. This is all I had to do to fix it in Windows XP:

  1. Find a .py file (any, even a blank).
  2. Right click on it and choose: "Open with>" and then select "Choose program...".
  3. This pops up a list of all programs - select python, and check the box "Always use the selected program to open this kind of file" and then click OK.

Checking this box resets file associations and fixes this problem for the command line.

The cause of the problem: Telling Windows to open up .py files in a text editor as default.

查看更多
萌系小妹纸
5楼-- · 2020-02-05 04:05

I've solved it! It's the command line to open a file .py.

It has to be like so:

"C:\Python27\python.exe" "%1" %*

mine was:

"C:\Python27\python.exe" "%1" without the final %* 

I've used FileTypesMan to edit because Windows 7 can't edit this property.

查看更多
够拽才男人
6楼-- · 2020-02-05 04:05

In my case it was solved by adding the path to django-admin.py.

The instruction in windows with a python 7 and django 1.11 is:

python c:\Python27\Lib\site-packages\django\bin\django-admin.py startproject mysite
查看更多
劫难
7楼-- · 2020-02-05 04:07

Gosh! It drove me crazy! Just do the following!

python C:\python27\scripts\django-admin.py startproject mysite
查看更多
登录 后发表回答