Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

macOS Ventura abd pyinstaller issue

Running on an M1 Mac-Mini with macOS Ventura and all updates.

I have a python (3.10.9) script that pulls data from a website which runs as expected.

I've bound it into an app using pyinstaller (5.7.0) and observed the following:

runs as expected when the single executable is dragged onto a Terminal window.,

runs as expected when the MacOS component of the app contents is dragged to the shell,

runs as expected when launched with 'open -a <my.app>,

fails when accessing website when launched by double-clicking the app.


I have verified that the environment variables are correct, and available to the module by logging them after retrieval.


My question is:

What's different between a double-click and open -a launches?

What can I do to correct or circumvent the issue?


Thanks for any help.


Mac mini 2018 or later

Posted on Feb 5, 2023 7:13 AM

Reply

Similar questions

6 replies

Feb 5, 2023 7:54 AM in response to oldmanwithbeard

Ensure that you have also installed the latest pyinstaller-hooks-contrib module:


pip3 install -U pyinstaller-hooks-contrib


I have a PyObjC application that I have built against Python 3.11.1, Pyinstaller 5.7.0, pyinstaller-hooks-contrib 2022.15, and PyObjc v9.0.1. My app works just fine when I double-click and launches with a scrollable window.


You want some of this (adapted to your code) in your pyinstaller .spec file for your Python application:


app = BUNDLE(exe,
             name='wexifx.app',
             icon='/Users/viking/Desktop/imanicon.icns',
             target_arch='universal2',
             bundle_identifier='com.VikingOSX.wexifx',
             info_plist={
                 'CFBundleIdentifier': 'com.VikingOSX.wexifx',
                 'CFBundleName': 'wexifx',
                 'NSPrincipalClass': 'NSApplication',
                 'NSRequiresAquaSystemAppearance': 'Yes',
                 'NSHighResolutionCapable': 'True',
                 'LSHandlerRank': 'Default',
                 'NSHumanReadableCopyright': 'Copyright © 2021-2023 VikingOSX. All Rights Reserved',
                 'LSMinimumSystemVersion': '10.13',
                 'CFBundleShortVersionString': '0.0.1'
             })


Once you have that squared away, you can issue:


rm -rf build dist
pyinstaller appname.spec


Feb 5, 2023 9:46 AM in response to VikingOSX

Bottom line: No joy.


I made the changes suggested by VikingOSX but the net change was that I screwed up my icon location and got a default one. Everything performed as described in the original post.


My original .spec file was a bit of a mismash cobbled together from bits and pieces of earlier attempts to build the app at all and then to try to resolve the current issue.


Many thanks for your suggestions.

P.S. I always run pyinstaller with the '-y' and '--clean' flags.

Feb 5, 2023 12:50 PM in response to VikingOSX

OK, I cleaned up a lot of detritus in the spec file and repositioned the logging statements.

The problem seems to be with access to the website, which is buried deep within the API class supplied b the vendor (AmbientAPI). Beyond ensuring the correct URL is passed to the API, I'm out of my depth.


Since the executable runs in the shell, I tried the trick of calling it from an Automator shell action. That usually works but in this case Automator just reports "Run Shell Script failed - 1 error". I'm not going down that rabbit hole.

Feb 16, 2023 11:47 AM in response to VikingOSX

As described earlier in this thread, my issue is that a pyinstaller built application runs perfectly when launched from the shell.


I believe the problem to be pyinstaller bound copy of the "requests" module does not behave the way the same module does when imported thro the system site library.


I tried making a local copy of the requests module and including it in the 'datas' entry in the specs file but that behaved the same way: no retrieval from the website.


I'm at a loss for a next move.

Feb 16, 2023 1:05 PM in response to oldmanwithbeard

I'm losing it. So deep in this rabbit hole I didn't realize that the hypothesis was wrong.

The executable module works just fine with the standard library.


A different launcher comes into play when an app is double clicked vs. offering the MacOS component to the shell. The question becomes:

is there anything I can do to my python script or the associated pyinstaller spec file?

is there some trick or option with the double-click method of launching?


Any help greatly appreciated.

macOS Ventura abd pyinstaller issue

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.