Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Python file by double-click

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.

like image 682
Bob Avatar asked Jan 13 '17 16:01

Bob


People also ask

How do I run a Python file in double click?

right click on the file->open with->choose default program->more options->select python.exe file and click on. Show activity on this post. Right click the file, select open with. If you want to simply run the script, find python.exe and select it.

Why doesn't Python run when I double click it?

Because double clicking is part of your operating system, and you need to ensure that your operating system knows what to do with python files. Remember that to the operating system, the python file is a simply a block of plain text (probably with a . py extension).


2 Answers

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.

like image 182
OregonTrail Avatar answered Sep 21 '22 07:09

OregonTrail


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

like image 33
ratna Avatar answered Sep 23 '22 07:09

ratna