ronaldoussoren / py2app

py2app is a Python setuptools command which will allow you to make standalone Mac OS X application bundles and plugins from Python scripts.
Other
342 stars 36 forks source link

The correct way to bundle ffmpeg binary #469

Closed octimot closed 7 months ago

octimot commented 1 year ago

Hello,

I'm trying to bundle ffmpeg using py2app for our tool (https://github.com/octimot/StoryToolkitAI) but can't seem to find the proper way to do it.

Technically, this would involve 2 things:

  1. The ffmpeg binary should be copied in Content/MacOS
  2. The bundled script (app.py) should use the new path (FFMPEG_BINARY if we declare it as an environment variable)

I've tried to include ffmpeg into the data_files variable:

data_files= [
        ('../MacOS/',
            ['venv/bin/ffmpeg'])
]

By doing this, the .app file will contain the ffmpeg binary in the MacOS folder, but the bundled python still prefers my local homebrew binary.

For no. 2 I could also define a os.environ['FFMPEG_BINARY'] manually in the app script, but I was wondering if there's a standard way to do it with py2app.

Obviously, I'm really new at this. So the question is, how should I tell py2app to fulfil these two things?

octimot commented 1 year ago

I just realized that I might be wrong with my assumption that the ffmpeg binary should be in the MacOS folder in the first place considering that the working directory is Contents/Resources.

ronaldoussoren commented 1 year ago

I'd just copy the file as a data file, and not worry about placing it in the MacOS folder.

I don't have a standard solution for your second question, that's something you should implement in your own code. But note that using environment variables like this is generally not something that fits into py2app's primary use case: creating macOS application bundles that are started by double clicking in the Finder.

octimot commented 1 year ago

Thank you for the reply!

I'd just copy the file as a data file, and not worry about placing it in the MacOS folder.

Understood!

I don't have a standard solution for your second question, that's something you should implement in your own code. But note that using environment variables like this is generally not something that fits into py2app's primary use case: creating macOS application bundles that are started by double clicking in the Finder.

The issue is that my app makes use of other packages / modules that need to be able to access ffmpeg and declaring the environment variable within my code is the only solution that I could find. I am calling py2app with ----emulate-shell-environment though, so it seems to work fine (so far). Is there something that could go terribly wrong in your opinion? Or would you recommend looking for a different approach?