Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App sharing does not work #492

Open
Demsli opened this issue Jun 11, 2023 · 33 comments
Open

App sharing does not work #492

Demsli opened this issue Jun 11, 2023 · 33 comments

Comments

@Demsli
Copy link

Demsli commented Jun 11, 2023

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?)

@ronaldoussoren
Copy link
Owner

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

@ronaldoussoren
Copy link
Owner

@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.

@StefanJordan
Copy link

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.

@Demsli
Copy link
Author

Demsli commented Jun 13, 2023

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"

@ronaldoussoren
Copy link
Owner

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.

@StefanJordan
Copy link

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.

@Demsli
Copy link
Author

Demsli commented Jun 13, 2023

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(

@StefanJordan
Copy link

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.

@Demsli
Copy link
Author

Demsli commented Jun 13, 2023

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
Copy link
Author

Demsli commented Jun 13, 2023

Will dmg make a difference?

@StefanJordan
Copy link

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.

@Demsli
Copy link
Author

Demsli commented Jun 13, 2023

"Application diviner can't be opened" :(

@StefanJordan
Copy link

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

@Demsli
Copy link
Author

Demsli commented Jun 13, 2023

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

@Demsli
Copy link
Author

Demsli commented Jun 13, 2023

  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(

@StefanJordan
Copy link

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

@Demsli
Copy link
Author

Demsli commented Jun 13, 2023

How can I check that xattr applied?

@ronaldoussoren
Copy link
Owner

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/.

@StefanJordan
Copy link

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.

@Demsli
Copy link
Author

Demsli commented Jun 13, 2023

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?

@StefanJordan
Copy link

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.

@Demsli
Copy link
Author

Demsli commented Jun 13, 2023

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
Copy link
Author

Demsli commented Jun 13, 2023

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.

@StefanJordan
Copy link

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...

@Demsli
Copy link
Author

Demsli commented Jun 13, 2023

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
Copy link
Author

Demsli commented Jun 13, 2023

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

@StefanJordan
Copy link

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

@Demsli
Copy link
Author

Demsli commented Jun 13, 2023

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
Copy link
Author

Demsli commented Jun 13, 2023

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
Copy link
Author

Demsli commented Jun 13, 2023

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)

@StefanJordan
Copy link

Yes, the problem is how to distribute it to people who are not very much into these technical steps. It would be good if one could bundle it in a way that the necessary steps are done automatically. Would a tool create a pkg file help in which a user could be just guided through the steps? I do not know such tools. I tried some packers but they did not work on Ventura.

@Demsli
Copy link
Author

Demsli commented Jun 13, 2023

Sandstrip is really easy to use. you just select file and it automatically deletes all quarantine tags. But yeah, wish these steps were unnecessary. Yesterday I updated to Ventura and downloaded Xcode. I read that it is possible to sign the app with just Apple ID. But not sure if it will work, the quarantine tag had Telegram in it. I bet that if I sent it to google disk the quarantine will remain, it probably gets added to anything that is not supported by Apple. Maybe dropbox will work? But for now the combo of stripper + app + some opening steps works.

@ronaldoussoren
Copy link
Owner

Standstrip is just a workaround. I will be looking into a better solution for this, but that will take time. A future version of py2app will also have direct support for code signing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants