+ 1

How do I run a python program by double clicking an icon instead of running it via the text editor?

16th Dec 2019, 2:10 PM
Hpec
2 Réponses
+ 1
1) if you're on linux/mac, you have to change file permissions (chmod) to make it executable, then add the so-called shebang line at the start of your file, e.g.: #!/usr/bin/python3 You'll most likely also have to look up how to set the PATH variable on your system to enable python. 2) on windows, you create a shortcut to your python.exe, then edit it in order to append the path to your filename.py. I recommend looking it up if the concept isn't clear to you, since it's hard to explain without screenshots/video. 3) alternatively, use this from cmd/terminal to create an executable: pyinstaller filename.py -F note that -F creates a single file instead of a folder containing multiple files. you can also append "-i filename.ico" to give it an icon. for further information, I recommend the pyinstaller documentation. Note: option #3 will create an application that runs on any computer, even if python isn't installed. the other options obviously require python installed on your system.
17th Dec 2019, 5:26 AM
grdr
0
You can't do this unless you do one of the following: Compile your python code to machine readable format. or Write an bash script to run the program with the help of the python interpreter.
16th Dec 2019, 2:35 PM
Leno
Leno - avatar