Closed Y4rd13 closed 1 year ago
This can be related to the architecture, but also on the macOS version.
If you installed Python using an installers from www.python.org the Python interpreter supports macOS 10.9 or later, but most other distributions are far more targeted (AFAIK homebrew installs a Python that works on the OS version of your machine, or newer). This limitation is inherited by the app bundle you create, and that's made slightly worse by some wheels targeting fairly recent macOS versions as well.
Py2app will get a feature that reports on this in the future, but I don't know when.
Hi @ronaldoussoren , indeed with was related to the arch, bujt also to the python framework. Finally I did a short documentation that was what helped me to build the app successfully and distribute it between different macos. I'm not a mac dev, hope it is helpful for anyone else!
Note: for each architecture we recommend to use a diferent virtual enviroment.
Look where is your python framework installed (install it directly from the package in https://www.python.org/downloads/macos/
Create a virtualenviroment, activate it and install the dependencies
python3 venv env
source env/bin/activate
pip3 install -r requirements.txt
If the deployment is for x86_64 architecture, you can install the dependencies with the following command:
arch -x86_64 python -m pip install -r requirements.txt
arch -x86_64 python setup.py py2app --arch x86_64 # to build
/Library/Frameworks/Python.framework/Versions/<version>/lib/
) and copy the tcl8
, tcl8.6
and tk8.6
into your virtualenv (env/lib/
) folder.setup.py
and change the executable path for python (it is a variable called executable_stub
) and change it for what's yours.
For example:executable_stub: "/Library/Frameworks/Python.framework/Versions/3.9/libpython3.9.dylib"
setup.py
remember to check in the class CONFiG
the version, the platform and architecture to deploy.python3 setup.py py2app
dist/<name>.app
foldernano /dist/<name>.app/Contents/Info.plist
and change the PyRuntimeLocations
to the one you have in APP...
<key>PyRuntimeLocations</key>
<array>
<string>@executable_path/../Frameworks/Python.framework/Versions/3.9/Python</string>
</array>
...
./dist/<name>.app/Contents/MacOS/<name>
or double click in the app to test it.Now you need to zip your <name>.app
or the dist/
folder. The problem is in here, since zipping in the standard way this app is corrupting the files
There a couple of options that I think you can do:
open dist/
, then in the Finder window that comes up, right click on the app and compress itcd dist; zip -yr $NAME.app.zip $NAME.app
another option is to convert the <name.app>
to a <name>.dmg
file using your disk utility (you can find this option in the File
menu) and then compress the .dmg
file.
observation: (if you use the zip command line tool, you must use the -y option) without it, your downloadable app bundle will be somewhat mysteriously broken even though the one before you zipped it will be fine.
cc @ronaldoussoren
I'm reopening the issue because your write-up shows that something isn't working as it should, and that's something I want to investigate further.
In particular, py2app is supposed to do "II. Build the app" completely automatic, even for "Universal 2" apps that support both x86_64 and arm64. That said, for Universal 2 the success of this depends on which 3th-party libraries you use, as not all projects ship universal2 wheels (sadly).
This might be related to the usage of homebrew, that's not something I regularly test with as I don't use it myself. I prefer using the installers on python.org and wheels from PyPI, and don't have need for other software that's distributed through homebrew.
BTW. "zip -y..." is necessary because app bundles created by py2app contain symbolic links and zip won't include those as symbolic links without the -y
flag.
@ronaldoussoren I see! Also I discover that if you are not a MacOS developer (for that you need to pay a subscription, etc). You can distribute the app in this way I meantion, but also you need to run sudo xattr -rd com.apple.quarantine <APP>
in the shared machine. Otherwise it will not run, since apple will not found the registered developer (unkown developer
warning).
Btw it is worth to mention that there's a docker-osx image that you can run different MacOS distribution! So you can simulate different OS enviroments. Of course will be always better do this directly from the shared machine, in case it uses a different architecture. But for anything else, the docker image is useful.
I have built an app using Tkinter and when I compile it using
python setup.py py2app
it works on my mac, but it won't work on other macs. This happen when I zip the folder dist and send it to another computer.Can this be related to the architecture? ARM based now with the M1 chips, which wont work with x86?
The zip creates a
DS_Store
file:Traceback:
This is how the
setup.py
looks like: