Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.py file opens PyCharm instead of running the script

I have written a python script (lets call it myTest.py) and would like to launch it from the windows command promt.

My python interpreter was added to the PATH environment variable, therefore i can launch it just fine as python myTest.py and it is executed successfully.

I would however like to launch it by simply typing myTest.py in the command promt. But if I do this, the file is opened in PyCharm and is not executed.

I have checked assoc .py which gives me .py=Python.File, as well as ftype Python.File which gives me Python.File="C:\WINDOWS\py.exe" "%L" %*. As far as I understand this, a .py file should be launched with py.exe at the given path. (If you are as confused as I was by the %L option of ftype, that is not mentioned in its help document: It makes no difference in my case and is equivallent to %0 and %1. Source: https://mail.python.org/pipermail/python-list/2015-November/699263.html)

Can anyone explain why my script is opened in PyCharm and not launched with py.exe? What do I have to do to simply execute it instead?

Edit: The answer of @Hamed169 solves the problem (thanks!), but doesnt't give any details on why there is a difference between the program that is used to open a file and the one that is returned by ftype. For everyone that is interested in why there is a difference I have found the following question (has currently no final answer, but quite a bit of information): https://superuser.com/questions/204354/how-do-i-get-ftype-assoc-to-match-windows-explorer

like image 692
AlbertM Avatar asked Oct 27 '18 22:10

AlbertM


1 Answers

Right Click on a .py file

Click Properties

Click "change" in Opens with:

Select your python interpreter instead PyCharm

Run your .py files and enjoy:)

like image 93
Hameda169 Avatar answered Oct 08 '22 00:10

Hameda169