1

I have a simple hi.py python script

print "hi there, everyone!"

I can run that script at the Windows cmd by explicitly invoking the interpreter and give my script as input parameter:

C:\>python hi.py
hi there, everyone!

C:\

This implies that my path is set correctly to find the python interpreter, and that the python script hi.py is valid.

Now my objective is to run the script hi.py such that windows command implicitly finds the python interpreter. This is a feature that, as I understand correctly, should work out of the box. However, for some reason not with my Windows 7 installation, that responds as follows:

C:\hi.py
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\

Does anyone knows what is messed up here? Thank you for your time!

0

3 Answers 3

1

How do you know that you have associated files of type *.py with the interpreter? You need to make sure that the association is correct in the control panel.

Sign up to request clarification or add additional context in comments.

3 Comments

...or just right click on hi.py => open with... => python.exe. Ensure that 'always use the selected program to open this kind of file' is checked.
@unwind: Indeed I have associated '*.py' to the python interpreter. For instance, if I double click a .py file, it opens up a command window and starts running the python script.
@plbt5, don't do this since it won't necessarily be configured to pass command-line arguments. Instead open an administrator command prompt and run assoc .py=Python.File and then ftype Python.File="Path\To\Your\python.exe" "%1" %*. (The %* is for command-line arguments.) Next delete the automatically configured registry keys: reg delete "HKCU\Software\Classes\Applications\python.exe" and reg delete "HKCU\Software\Classes\.py". Ignore errors if the keys don't exist. Hopefully when you log off and back on Explorer will use the Python.File ProgId.
0

you need to specify the interpreter at any cost, if you don't then the computer wont know whether you want to run the script or edit the script

Comments

0

That is probably because you have .py files associated with cmd.exe. You can check that (and modify accordingly) from Control Panel -> Programs -> Default Programs -> Set Associations (Associate a file type or a protocol with a program).

1 Comment

This might be the reason why the failure occurs. I see that .py is associated with the Windows Commander, as opposed to python.exe as I suspect it shoud've been. I cannot, however, change this; apparently that is out of my priviliged control - I will take this up with our system administrator.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.