py2app
py2app copied to clipboard
Need help getting py2app to work
I have tried many different formulations but, I can't get py2app to produce a working app.
My main problem is that I know almost nothing of Python. I have developed an AppleScript applet which provides a GUI “frontend” for a Python script provided by another developer.
The applet runs on any version of macOS from OSX 10.10 up. My applet works because it relies on the Python2.7 framework provided by Apple in macOS. However, development of the script has recently ceased.
I need to move my applet to another script that does the same thing and is actively developed. But, the new script requires Python3.6+. I have looked at creating a Python runtime but, after days of trial and error could not get anything to work.
As an alternative py2app looks really good as it would simplify installation for my users. But, I can't get it to work. The best I got was an app which failed when run from Terminal. It threw "Permission denied" and if I sudoed: "command not found".
I'm totally lost. It seems that I can't pass a folder to py2app – it will only create an app if a single Python script is passed to it – otherwise I get this: "error: [Errno 21] Is a directory:".
I'm not even sure whether the "APP" variable is a literal name of the app or the path to a Python script named for the app. I tried both but it failed with various errors such as 'No such file or directory'. Every time py2app produced what looked like an executable, I got a "zsh: permission denied:" error in Terminal when I tried to run it.
The Python source code I have does not contain a script named for the app. It has a setup.py as well as a folders containing "__init__.py" and a "__main__.py". It has no extra "data" – that is, it is designed to run from the Terminal; has no icon or language files; etc. it's just a mass of around 900 scripts tied together.
I have read thru the py2app Tutorial and other materials and tried various ideas provided in "Examples" folder. I have to admit that I don't understand quite a lot – as said, I'm not a Python developer.
I would greatly appreciate any clues on what I might be doing wrong.
You are jumping into the deep end of the pool here ;-).
Py2app is generally focussed on create application bundles for GUI apps, and is less suited for bundling command-line scripts. That said, it should be able to do what you need.
Bundling yt-dlp looks doable, I might have some time to look into this during the weekend.
The steps below are completely untested at the moment.
- Create a script "main.py" with the following content:
import youtube_dl
if __name__ == '__main__':
youtube_dl.main()
- Create a file named "setup.py" with the following content:
import setuptools
setuptools.setup(
name="yt-dlp",
app=["main.py"],
setup_requires=["py2app"],
)
~
-
Create a virtual environment: ```python3 -mvenv build-environment``
-
Activate that environment:
source build-enviroment/bin/activate.sh
-
Install some required packages:
python3 -m pip install -U py2ap mutagen pycryptodome websockets
-
Run py2app:
python3 setup.py py2app
If all goes well the application will be dist/yt-dlp.app, and you can run it from the command-line as dist/yt-dlp.app/Contents/MacOS/yt-dlp
.
The application also requires tools like ffmpeg, those aren't build/installed by the procedure above.
You are jumping into the deep end of the pool here ;-).
Yes, and I fear the bottom is muddy. Many thanks for all this. I'll take a look soon.
The lead developer of YT-DLP put me on to PyInstaller (they don't have access to a Mac and so can't do this work). I've managed to use that to build copies of YT-DLP which works on macOS without a Python3 install. There seems to be a bug in PyInstaller when run on High Sierra but, the developers are actively working on it (their bug is partly due to a bug in macOS which has to be worked around).
Cheers.