Issues running python scripts in Command Prompt (Specifically with command line arguments)?
I am trying to run my python scripts in the command-prompt without calling python.exe first. I am specifically doing this in relation to running django-admin.py. I have C:\Python26 and C:\Python26\Scripts in my PATH. However, if I try running django-admin.py by doing:
django-admin.py startproject helloworld
I get the message: Type 'django-admin.py help' for usage.
Now, after some experimentation, I realized the problem is that the secondary arguments to these scripts are not being passed for some reason, since I tried it with a some other python scripts I have. I know I could avoid this problem by simply doing:
python C:\Python26\Scripts\django-admin.py startproject helloworld
But I know it should be possible to run the first command only and get it to work, because I had it working before. I'v开发者_运维技巧e looked everywhere, and not many places have been helpful so any idea would be useful for me at this point.
Update: The .py file associations were set correctly, and the problem is still occuring.
Check assoc
and ftype
. If properly set, you can run a .py
with arguments.
> assoc .py .py=Python.File > ftype Python.File Python.File="C:\Python26\python.exe" "%1" %*
Depending on how your Python was installed, these may or may not be in place. You can set them with assoc
and ftype
.
> assoc .py=Python.File > ftype Python.File="C:\Python26\python.exe" "%1" %*
Also, if .py
is included in the PATHEXT
environment variable, you can run .py
files without the trailing .py
.
> set PATHEXT=%PATHEXT%;.py > django-admin startproject helloworld
I know this is an old thread, but I have searched for a few weeks for this very same problem and found nothing. Today, however, I tried something new:
If you are using Windows 7, do not use Command Prompt for scripting purposes.
Instead, use the Windows PowerShell located at: All Programs -> Accessories -> Windows PowerShell -> Windows PowerShell
. In there you can run the command django-admin.py startproject mysite
if you added the correct paths to your environmental paths.
BTW, I'm now using Python 2.7 with Django 1.2.4 on Windows 7 Ultimate 32bit.
精彩评论