Run Python Script on any Mac computer

htmlpythonterminal

Is there a way to create an executable Python script that will be able to run on any Mac via terminal, similar to a Bash script. I need any user to be able to just double click the file, and it should run. I want it to be able to run without the user having Python installed, but it has to be a Python script as it has to interact with an HTML button.

Best Answer

You can use PyInstaller, which is a free program that does the exact thing you want. As the official website says:

PyInstaller is a program that freezes (packages) Python programs into stand-alone executables, under Windows, Linux, Mac OS X, FreeBSD, Solaris and AIX. Its main advantages over similar tools are that PyInstaller works with Python 2.7 and 3.3—3.5, it builds smaller executables thanks to transparent compression, it is fully multi-platform, and use the OS support to load the dynamic libraries, thus ensuring full compatibility.

I should also mention that you can make a .py file executable just like other Linux(Unix) executable file, like this:

This command lets the file to be executed(see this)

user@linux~>chmod 0755 myProg.py

and then run it like this:

 user@linux~>./myProg.py