問題描述
為什麼使用 py2app 模塊創建 mac 文件時出現錯誤? (Why i am getting Error when creating mac file using py2app module?)
我正在嘗試將 Tkinter python 文件轉換為 dmg 或 mac os 文件。但是,當我在終端中鍵入 python setup.py py2app ‑A 時,出現以下錯誤 *** 創建應用程序包:MyApplication *** 錯誤:[Errno 1] Operation not allowed: '/Users /mohamedthoufeeq/dist/MyApplication.app/Contents/MacOS/MyApplication' 請幫我解決這個問題。
Mohameds‑MacBook‑Pro:~ mohamedthoufeeq$ python setup.py py2app ‑A
running py2app
creating /Users/mohamedthoufeeq/build/bdist.macosx‑11.0‑x86_64/python2.7‑standalone/app
creating /Users/mohamedthoufeeq/build/bdist.macosx‑11.0‑x86_64/python2.7‑standalone/app/collect
creating /Users/mohamedthoufeeq/build/bdist.macosx‑11.0‑x86_64/python2.7‑standalone/app/temp
creating build/bdist.macosx‑11.0‑x86_64/python2.7‑standalone/app/lib‑dynload
creating build/bdist.macosx‑11.0‑x86_64/python2.7‑standalone/app/Frameworks
*** creating application bundle: MyApplication ***
error: [Errno 1] Operation not permitted: '/Users/mohamedthoufeeq/dist/MyApplication.app/Contents/MacOS/MyApplication'
參考解法
方法 1:
Four possible answers:
- Write
python3
instead ofpython
- Disable SIP as it may mess with the permission end (what your error suggests)
Reboot the Mac and hold down Command + R keys simultaneously after you hear the startup chime, this will boot Mac OS X into Recovery Mode When the “MacOS Utilities” / “OS X Utilities” screen appears, pull down the ‘Utilities’ menu at the top of the screen instead, and choose “Terminal” Type the following command into the terminal then hit return:
csrutil disable; reboot
You’ll see a message saying that System Integrity Protection has been disabled and the Mac needs to restart for changes to take effect, and the Mac will then reboot itself automatically, just let it boot up as normal
- Remove the restricted File Flag
sudo chflags ‑R norestricted /System/Library/Frameworks/Python.framework
- Uninstall py2app and reinstall it
pip3 uninstall py2ap
pip3 install ‑U py2app
(by Thoufeeq、Altay Akkus)