Take the 2-minute tour ×

I have both Python 2.7 and Python 3.3 installed on my machine (I'm on Windows 8).

I would like .py files to be opened with Python 3.3 by default. The only Python path in the PATH environment variable is the 3.3 one. Still, when opening .py files I see they're being interpreted by Python 2.7, even when I explicitly open them with the Python 3.3 exe ("Open with" and choosing the 3.3 exe). I've also tried changing the Python.exe version using "Set Associations" in Windows' control panel. I'm not sure it has changed anything. No matter what I do, the output of the following program is 2.7.3:

import sys

How do I force Windows 8 to open .py files with Python 3.3?

share|improve this question

migrated from stackoverflow.com Jun 12 '13 at 22:20

This question came from our site for professional and enthusiast programmers.

How do you open them? By double clicking? Are they executed right away in a console window, or got picked up by IDE (i.e. IDLE)? –  J0HN Jun 12 '13 at 19:51
@J0HN: I open them by double clicking and they're being opened with a console window. I've also tried right clicking and choosing "open with" with the 3.3 version. –  snakile Jun 12 '13 at 19:52
launch interactive interpreter by typing just python in console, than run the code from the question. If it still output 2.7.3 your path points to the wrong python interpreter. Or, even better, just type python -V in console –  J0HN Jun 12 '13 at 19:53
@J0HN: Thanks, both your suggestions do work and output 3.3 as desired. But even when I start the .py file using Windows command line shell it outputs 2.7. –  snakile Jun 12 '13 at 19:57
haven't used python in windows for years but check these env-variables: %PATH%, %PYTHONPATH%. Have a look at msconfig and autoexec.bat. –  Fredrik Pihl Jun 12 '13 at 19:57

4 Answers 4

Try to add #!python3 to the very first line. Python 3.3 introduced Python Launcher for Windows that associates .py with c:\windows\py.exe. It launches the highest Python 2 by default.See http://stackoverflow.com/a/17245543/1346705

share|improve this answer

If you want to change the IDLE used when right clicking you can go into the registry and find the key:

HKEY_CLASSES_ROOT\Python.File\shell\Edit with IDLE\command

You should see something like:

"C:\Python27\pythonw.exe" "C:\Python27\Lib\idlelib\idle.pyw" -e "%1"

Change all the 27 to 33 if you installed your pythons in the default area. If not just change the path to where your 3.3 implementation is stored.

To change the default command line python you should do the same with the path in your PATH environment variable.

share|improve this answer

Have you tried uninstalling Python 2.7 temporarily? That might fix the file association. I am uncertain, as I am not familiar with Windows 8 beyond what little I learned of it when I tried it on someone else's computer. I'm not even sure it would work on Windows 7, but it is worth a shot if you ask me.

I also recommend using the tag for the specific version of Windows you are using, rather than the standard "windows" tag. In this case, I might use both, since file associations don't change much between versions of Windows. At least use the correct tag (windows-8), at any rate. Then you will get more answers from people looking for that tag.

share|improve this answer

It seems that windows is not checking the whole path of the executable! Try to rename the python.exe of version 2 (respectively 3) to some temp name. Then associate with this name. And change everything back.

FYI you could check the file association with:

C:\Users\shadowed>assoc .py

C:\Users\shadowed>ftype Python.File
Python.File="C:\Python27\python.exe" "%1" %*
share|improve this answer

Your Answer


