py2app icon indicating copy to clipboard operation
py2app copied to clipboard

App sharing does not work

Open Demsli opened this issue 2 years ago • 48 comments

Greetings everyone. I am trying to freeze my program and share it with my colleagues. When I freeze the program on my MacBook Air M2 - the program works. But as soon as I compress it into the zip folder and share it (for example via telegram or google disk) I get a message "The application can't be opened". When going into the contents of the app, into macOS folder and launching the unix file I get an error that the file is damaged and should be deleted. I am doing this testing of download and unpackaging on the same Air, which is even more weird why this occurs, since it is the one that build the app. Can it be the problem of app signing? Py2app version: 0.28.5 Python version: 3.11.3 macOS version: 12.5 setup code: from setuptools import setup

APP = ['diviner.py'] DATA_FILES = [] OPTIONS = {'iconfile': '/Users/profix/PS-mac.icns'}

setup( app=APP, data_files=DATA_FILES, options={'py2app': OPTIONS}, setup_requires=['py2app'], ) Program code: import tkinter as tk

def divide_by_two(): try: # Get the number from the entry widget number = float(entry.get())

    # Divide the number by two
    result = number / 2
    
    # Update the label with the result
    result_label.config(text=f"Result: {result}")
except ValueError:
    # Display an error message if the input is not a valid number
    result_label.config(text="Invalid input")

window = tk.Tk() window.title("Number Divider") window.geometry("200x200")

entry = tk.Entry(window) entry.pack()

button = tk.Button(window, text="Divide by 2", command=divide_by_two) button.pack()

result_label = tk.Label(window, text="Result: ") result_label.pack()

window.mainloop() The program is simple, I am just using it as a test to see how freezing on Mac works. The app freezes, but what's the point if I cannot share it with my friends?)

Demsli avatar Jun 11 '23 11:06 Demsli

Does this error also occur when you open the zipfile locally and launch the application?

ronaldoussoren avatar Jun 13 '23 09:06 ronaldoussoren

@StefanJordan mention in #493 that removing extended attributes can help (xattr -cr /path_to_App/App.app in the terminal).

That points to the macOS quarantine system interfering. I hope to have time over the summer to investigate this fully and work on a better solution.

ronaldoussoren avatar Jun 13 '23 09:06 ronaldoussoren

Is there a way to pack the dmg file in a way that the user is asked to go into the Mac setting in order to allow the app to be launched? I did not find this information anywhere and some free programs to pack the dmg did not work for me.

StefanJordan avatar Jun 13 '23 09:06 StefanJordan

Does this error also occur when you open the zipfile locally and launch the application?

Nope, compressing and decompressing immediately works. Downloading the zip from external source causes the issue of "Not being able to open"

Demsli avatar Jun 13 '23 19:06 Demsli

Either remove extended attributes from the app bundle (see my previous comment), or try opening using the context menu (right clicking) instead of double clicking. The latter tends to be more forgiving in what it accepts, especially when app bundles are not signed using a developer ID.

ronaldoussoren avatar Jun 13 '23 19:06 ronaldoussoren

Despite trying to solve the problems by opening the App with a right-click, I was unsuccessful. However, when I distributed the app as a dmg file and asked to relocated it to a different location, three individuals were able to open it after applying the command "sudo xattr -cr /path/App.app". All of these steps were performed on Ventura 13.4.

StefanJordan avatar Jun 13 '23 19:06 StefanJordan

Either remove extended attributes from the app bundle (see my previous comment), or try opening using the context menu (right clicking) instead of double clicking. The latter tends to be more forgiving in what it accepts, especially when app bundles are not signed using a developer ID.

xattr -cr gave me an error "option -r not recognized", so I used xattr -c. Still same error(

Demsli avatar Jun 13 '23 19:06 Demsli

Demsli, did you pack it into a dmg image first? It did not work without doing it because the file got corrupted whenever a zip was involved in the distribution! Maybe tar would work but I am not sure.

And do not apply it to the dmg file, of course, but to the app. Maybe it does not always work with this method but I was successful with it.

StefanJordan avatar Jun 13 '23 19:06 StefanJordan

I applied it to the file and tried to zip it. Tried the sudo method as well - now after unpacking from download it says "file not found" though the app is there. Weird

Demsli avatar Jun 13 '23 19:06 Demsli

Will dmg make a difference?

Demsli avatar Jun 13 '23 19:06 Demsli

Yes, it made the difference between it works and it does not work. Drag the folder onto the Disk Utility-icon, or choose "New->Disk image" from folder in the File-menu in Disk Utility.

StefanJordan avatar Jun 13 '23 19:06 StefanJordan

"Application diviner can't be opened" :(

Demsli avatar Jun 13 '23 19:06 Demsli

Did you extract the app from the dmg file AND applied "sudo xattr -cr /path/App.app"?

StefanJordan avatar Jun 13 '23 19:06 StefanJordan

My bad, thought that I had to apply first, dmg it and then send. Will try this order

Demsli avatar Jun 13 '23 19:06 Demsli

  1. Ran python3 setup.py py2app
  2. Disk Utility -> New image from folder -> .app
  3. Sent diviner.dmg to telegram and downloaded back to the machine
  4. opened diviner.dmg and got the file out
  5. In terminal located the folder
  6. Applied sudo xattr -c diviner.app
  7. Still got the error that diviner can't be opened(

Demsli avatar Jun 13 '23 19:06 Demsli

create app -> packing app into dmg -> deliver -> unpack app -> move to its destination -> apply "sudo xattr -cr /path/App.app"

StefanJordan avatar Jun 13 '23 19:06 StefanJordan

How can I check that xattr applied?

Demsli avatar Jun 13 '23 19:06 Demsli

Did you extract the app from the dmg file AND applied "sudo xattr -cr /path/App.app"?

The sudo part should not be necessary if the app bundle is owned by yourself (that is, not a system binary).

Also for anyone not familiar with the command-line, please use a tool like "standstrip" to remove unwanted extended attributes: https://eclecticlight.co/xattred-sandstrip-xattr-tools/.

ronaldoussoren avatar Jun 13 '23 19:06 ronaldoussoren

I have no idea. Try opening it with the right mouse click. I only can tell what worked for me with my app and three others who are using it.

StefanJordan avatar Jun 13 '23 19:06 StefanJordan

I have no idea. Try opening it with the right mouse click. I only can tell what worked for me with my app and three others who are using it.

do you have the arm based MacBook or intel one? can the architecture be the case?

Demsli avatar Jun 13 '23 19:06 Demsli

Mac Book Pro with M1 in my case. And Ventura 13.4 in my case and in the case of the ones who use the app. I am not sure whether they have Intel or M1/M2.

StefanJordan avatar Jun 13 '23 19:06 StefanJordan

Did you extract the app from the dmg file AND applied "sudo xattr -cr /path/App.app"?

The sudo part should not be necessary if the app bundle is owned by yourself (that is, not a system binary).

Also for anyone not familiar with the command-line, please use a tool like "standstrip" to remove unwanted extended attributes: https://eclecticlight.co/xattred-sandstrip-xattr-tools/.

checked the file after extraction with xattred. It did have com.apple.quarantine tag with string 0187;6488c803;Telegram; attached. Tried to cut it - it created com.apple.provenance tag, but did not solve the problem, the app still does not open:(

Demsli avatar Jun 13 '23 20:06 Demsli

Tried sandstrip, got a new error - “diviner” can’t be opened because Apple cannot check it for malicious software. Unix file in contents/macOS folder showed a bit more info - diviner” cannot be opened because it is from an unidentified developer.

Demsli avatar Jun 13 '23 20:06 Demsli

Maybe you could follow https://iboysoft.com/news/app-is-damaged-and-cannot-be-opened.html#how-to-fix-fileapp-is-damaged-and-cannot-be-opened-on-macos-venturabig-sur If you are experiencing "App is damaged and cannot be opened" on macOS Ventura, do the following steps to fix it:

Open the Apple menu > System Settings. Select Privacy & Security > Developer Tools. Click the ( + ) button and navigate to the folder where the damaged app resides. Select the app and click Open. If you are encountering "Application is damaged and cannot be opened" on Big Sur/Monterey/Catalina when opening an app, try these steps:

Open the Apple menu > System Preferences. Select Security & Privacy. Tap the yellow lock and enter your password to unlock the preference pane. Click "Open Anyway."

Maybe this help. I have no idea...

StefanJordan avatar Jun 13 '23 20:06 StefanJordan

Tried sandstrip, got a new error - “diviner” can’t be opened because Apple cannot check it for malicious software. Unix file in contents/macOS folder showed a bit more info - diviner” cannot be opened because it is from an unidentified developer.

Update - right clicking on the app to open after it was stripped allowed to click open. The app now works. Yahoo!

Demsli avatar Jun 13 '23 20:06 Demsli

I will try to use the zip method. I will also see if stripping the archive works

Demsli avatar Jun 13 '23 20:06 Demsli

Congratulations! I am relatively sure that zip does not work because I made several tests but maybe I am wrong.

StefanJordan avatar Jun 13 '23 20:06 StefanJordan

Stripping the archive itself and unzipping also works. Will try to upload the stripped archive again. To see if it will have the quarantine tag the second time

Demsli avatar Jun 13 '23 20:06 Demsli

Yes, sending the stripped archive adds the tag again. So, in order to share the program, the steps are:

  1. Freeze the code
  2. Compress the app into .zip archive
  3. Send the .zip to a friend
  4. Friend unzips the file
  5. Uses Sandstrip to strip the quarantine tag
  6. Opens the app to receive the error of unidentified app
  7. Right clicks the app and selects open
  8. Now in the error window the second option "Open" will appear
  9. Clicking "Open" in the window will open the app. Now the system trust the app and it can be opened at any time.

Demsli avatar Jun 13 '23 20:06 Demsli

Will probably have to bundle the .zip archive with the Sandstrip and the text readme file with necessary steps. Will also test the original program I needed to freeze. Thank you StefanJordan and ronaldoussoren for the help. Struggled with this thing for a while but glad that a solution was found)

Demsli avatar Jun 13 '23 20:06 Demsli