How to convert python file to executable file on Mac machine?
Three possibly answers occur to me:
- you just want your Python script to be executable as a command
MacOS is a UNIX platform; these instructions work for any UNIX or POSIX
platform (MacOS, Linux, the various other UNIXen).
Just make your script an executable file:
Make the first line of the script be “#!/usr/bin/env python3”. This
tells the OS how to invoke the script i.e. via the python3 interpreter.
Make the script readable and executable:
# give yourself read+execute chmod +rx your_script
This makes the script executable as a command (the “x” permission) and
readable (the “r” permission, required for Python to run it). If other
people are also expected to execute the script:
# give all users read+execute chmod a+rx your_script
If the script is to be not just executable, but useable as an ordinary
command, put it in a directory named in your $PATH variable. You can see
Common practice for personal commands is to make a personal directory
Put the script in there. Ensure that directory is also in your $PATH:
Put that command in your $HOME/.profile file if you always want it -
that should be run when you log in.
- you want to make a Mac “application”
This requires use of a tool like py2app. You’ll almost certainly need
XCode as well (the MacOS compiler suite).
- you actually want a Windows .exe file
The application bundling tools I’m aware of for that need to run on
Windows because they need the Windows compiler suite.
Cameron Simpson firstname.lastname@example.org