My pyw file opens in text editor instead of running the app

Hi,

I am not a Python pro by any means and this seems like it should have a simple solution but I can’t find it anywhere.
I have a pyw file with a simple tkinter script and when it runs the tkinter window pops open. That is how it worked until recently. Now when running the file it opens up the text editor.

I recently had a new install of Python on my computer. My office has ArcGIS Pro and ArcMap and as part of those installs both Python 2.7 and Python 3.4 are installed on my computer. Recently a new version of Pro was installed so my Python version 3 was replaced. That must have something to do with it but I can’t figure out how.

I have tried setting the default app to python.exe and pythonw.exe in both the Python 2.7 and 3.4 and none of those have worked.

Please help.

Thank you

This just works for me.

What do these commands report?

C:\Users\barry>assoc .pyw
.pyw=Python.NoConFile

C:\Users\barry>ftype Python.NoConFile
Python.NoConFile="C:\WINDOWS\pyw.exe" "%L" %*

And here is a test for the invokation:

C:\Users\barry>type tmpdir\q.pyw
import time
with open(r'\Users\barry\tmpdir\a.log', 'w') as f:
    f.write(f'pyw running {time.time()}\n')

C:\Users\barry>tmpdir\q.pyw

C:\Users\barry>type tmpdir\a.log
pyw running 1732615041.033967

C:\Users\barry>tmpdir\q.pyw

C:\Users\barry>type tmpdir\a.log
pyw running 1732615057.715728

As you can see the time changes each time I run q.pyw script.

The first command:
“assoc .pyw” reports…
.pyw=Python.NoConFile

But “ftype Python.NoConFile” reports…
File type ‘Python.NoConFile’ not found or no open command associated with it.

You can set the command with:

ftype Python.NoConFile="C:\WINDOWS\pyw.exe" "%L" %*

I apologize for my ignorance. But are you saying to copy that into cmd? Because if I do, I simply get an error saying “File type ‘Python.NoConFile’ not found or no open command associated with it.”
image

What does:

ftype Python.File

print?

On my computer it prints:

Python.File="C:\Windows\py.exe" "%L" %*

and:

ftype Python.NoConFile

prints:

Python.NoConFile="C:\Windows\pyw.exe" "%L" %*

I’d have to open the Command Prompt as Administrator to set them.

I think you can override on a user basis.