1

(In windows)

I have both Python 2.6 and 2.4 installed on a machine (for testing purposes). When I open a cmd and type python I get:

C:\>python  
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.  

However, when I create a file named test.py with contents

import sys  
print(sys.version)

It displays:

C:\temp>test.py  
2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]

Why would this be? I've checked my path and I have c:\python26 in there. It seems .py files are associated with python 2.4. I would expect that to by an environment variable, but I don't see it anywhere. I did install 2.4 after 2.6, so this makes some sense, but is there a list somewhere of what filetypes are associated with what executables?

3 Answers 3

4

You need to review your file associations. In Windows Explorer choose Tools > Folder Options. On the File Types tab go find the .py extension and set it to the correct interpreter.

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

1 Comment

Or on modern versions of Windows, click the Start button, type "file association" and select "Change the file type associated with an extension".
2

The list is maintained in the registry, but you can use the ftype program to access it, e.g.

ftype | find "Python"

Or more properly:

C:\>assoc .py
.py=Python.File

C:\>ftype Python.File
Python.File="C:\Python26\python.exe" "%1" %*

2 Comments

Hm, I get: File type '.py' not found or no open command associated with it. That's odd.
Yep, sorry, try ftype | find "Python".
1

It's more likely to be a file association than a variable.

It can be easily fixed by reinstalling the later version of Python (you don't need to uninstall either version), which will update the associations to that one.

You can view file associations by clicking the Start button, typing "file association" and selecting "Change the file type associated with an extension". If you're on Windows XP, you need to open "Folder Options" from the control panel or an Explorer window.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.