Running Python file by double-click

Jack picture Jack · Jan 13, 2017 · Viewed 50k times · Source

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.

Answer

OregonTrail picture OregonTrail · Jan 13, 2017

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.