Mr_S_J_Childerley | 2020-10-15 08:23:47 UTC | #1
I've experienced several issues trying to generate an installation on macOS:
I was unable located two csv files that I put in the same directory containing main script, using the datas array. The main python script is run as an executable, on a mac after installation and the normal methods of getting location of the current script don't work! Is this why there is the nudge to use the qt resources system in the tutorial?
The size of installation was huge, in excess of 800Mb. I had assumed that pyinstaller just included imported modules, however in my case I found it had included modules relating to Jupyter notebook, QtNetwork, IPython, QtWebSockets none of which are referenced in my script. I am sure that none of my imports relied on these modules. After zipping 800Mb was reduced to a more manageable 277Mb.
Is there a Packaging tool for macOS. The tutorial targets windows nicely. What is the solution for mac users?
Unfortunately I am forced to question whether PyInstaller is fit for purpose on macOS.
martin | 2020-10-18 21:38:19 UTC | #2
Hey, thanks for posting this. Unfortunately packaging Python applications remains a bit of a painful experience when your applications get more complicated/have more dependencies. There are however things you can do do to improve things. I'll go through the questions one by one --
Paths in bundled apps
The path issue you mention is probably due to the "freezing process" for the app. See this in the PyInstaller documentation about how to get runtime information in a packaged app. See the note about file paths. If you use that approach for the paths, they should work identically bundled and unbundled.
How are you bundling your Mac app? To a single file, or a
.app bundle? If you use an
.app bundle, this is just a folder, so you can cd into it and have a look around.
This is why I hint towards resources, but you can definitely get it working without them.
This is a consequence of how Python works -- imports are dynamic, meaning you can import and access anywhere you want, conditionally, and from anywhere in your application. For example, if you import
PyQt5 you can then access
PyQt5.QtNetwork in your application without explicitly importing it. The bundlers avoid dealing with this by importing everything.
If you know there are modules you don't not need, you can use PyInstallers
excludes=) to exclude these from the bundle. Make sure you're not bundling tests.
macOS specific packaging tools
I've had the most luck with PyInstaller on macOS, but have also used py2app and cx_freeze with success. That said, they use the same bundling/freezing approach, and also produce the same size binaries.
Mr_S_J_Childerley | 2020-11-19 08:08:10 UTC | #3
Martin, many thanks for your detailed response which I need to go through thoroughly. However I run pyinstaller on macOS 11.0.1 (Big Sur) and got many of the following type of error, suggesting that perhaps Apple have moved stuff that PyInstaller was expecting to find?
14711 ERROR: Can not find path /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (needed by /Applications/anaconda3/envs/1ADC/lib/python3.7/site-packages/PyQt5/QtGui.so)
Perhaps suggesting I need a fresh installation of PyInstaller.
mike2750 | 2020-11-22 13:21:55 UTC | #4
I had similar issues when using fbs which uses pyinstaller but older versions.
I recommend installing the pyinstaller and Python like i mentioned here you might be able to get pyinstaller working with later Python 3.7 or 3.8 as they pushed some updates since but i have not setup a new test to see if they play nice like Python 3.6 does https://forum.learnpyqt.com/t/recommended-way-to-install-pyqt5-with-fbs-python-macos/525
I also have seen alot of people with issues when using anaconda vs standard python install so id recommend trying that too to see if it helps.