Running Python file by double-click

雨燕双飞 提交于 2020-01-13 08:16:17

问题


I have really annoying problem, I cannot run a Python file just by double-clicking.

I have tried to set it to open the file with idle.bat but that only starts IDLE editor on double-click, it does not run the Python file.


回答1:


What version of Python do you have installed?

You should write your own batch file to execute your python binary and your script.

For example, with a default Python 2.7 installation on Windows, this could be the entire contents of your script.

myscript.bat:

ECHO ON
REM A batch script to execute a Python script
SET PATH=%PATH%;C:\Python27
python yourscript.py
PAUSE

Save this file as "myscript.bat" (make sure it's not "myscript.bat.txt"), then double click it.




回答2:


Right click the file, select open with. If you want to simply run the script, find python.exe and select it. If you want to debug with IDLE, find that executable and select it.




回答3:


right click on the file->open with->choose default program->more options->select python.exe file and click on.




回答4:


When I had both Py2 and Py3, and then removed the former, my script wouldn't run by double-clicking it either (but fine from console.) I realized my __pycache__ folder (same directory as the script) was the issue. Problem solved when deleted.



来源:https://stackoverflow.com/questions/41639740/running-python-file-by-double-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!