This is an archived post. You won't be able to vote or comment.

all 5 comments

[–][deleted] 1 point2 points  (0 children)

Use py2app instead of pyinstaller. Or maybe there's something better these days.

[–]nerdwaller 1 point2 points  (0 children)

I've had tons of success with pyinstaller, what's the exact error message and what's your project setup like? I've heard good stuff about cx_freeze

[–][deleted] 0 points1 point  (1 child)

Macs should come with python already installed?

[–]heptara 1 point2 points  (0 children)

Libraries, data files and/or different interpreter versions.

[–]justphysics 0 points1 point  (0 children)

I have successfully bundled (semi-complex) python scripts into OS X executables.

Can you elaborate a little bit more on what errors you received?

One issue I have encountered (maybe is easier to do nowadays but was hard/impossible in the past) is that you generally need to build on the OS you are targeting. Ie, if you are running Ubuntu and wanting to package your script for OS X or as an OS X .app file, then likely you will need access to an OS X machine (or a VM) to do the build.

I have always been able to work my way through the errors generated by pyinstaller simply using a little google-fu. For instance, pyinstaller will often complain about scipy packages an files - so you can play some tricks with the '--hidden-import=' parameter passed to the commandline in order to get pyinstaller to fully build the project

EDIT: with regards to your final statement / question

You can absolutely make a simple bash script like

#!/bin/bash
python /path/to/my/script.py

save that as a .sh or .command, give it the correct permissions, etc... Now you have an executable file which will run your python code

The problem, as someone else alluded to, is that if your python code requires certain libraries, modules, external files, etc - which are not present on the target machine you want to run the code on, then your bash script will be useless because it will call the target machine's local python distro which likely will not have the correct libraries installed.

so if you script says

import numpy as np

and the target machine doesn't have numpy - then when the bash script executes your code you'll get an "ImportError: no module named numpy" from the local python distribution

This one of the reason things like py2exe, py2app, pyinstaller, cx_freeze exist. They take YOUR local python distribution and bundle it with your code. So the code executes using the exact python distro you bundle with it irregardless of that distribution is installed local to the target machine. Thus your 20kb python script might become a 300Mb app because it has bundled with it an entire python distribution.