Double click executable python script on Mac! Here is how I did it.
The easy way. No extra app installation needed.
1 min read
Let's agree that exciting your Python script by double clicking it on a Mac is super cool. It's a way to convinently run your code without opening Terminal going to your folder and typing
python code.py then closing it.
It also doesn't look easy when showing it to your friends who aren't into coding.
There are two ways. In fact there are many. Trust me, I have searched everywhere and tried all of them.
The easiest by far, that doesn't include installing Py2app and running into Launching errors is the following:
- Add this standard line at the beginning of your code
#!/usr/bin/python #if python3 is the only Python on you computer
Change file name to
myPythonCode.toolinstead of the normal
Give permission to execute the code by inputing the following code in the terminal to change permission
chmod +x myPythonCode.command
That's basically it. Py2app could work for you with some kinds of Python applications. I personally found this way the quickest and most convenient.