python 打包的程式在 macOS 會閃退

並不是使用 py2exe 打包為.app, 是使用platypus,網路上查到的解法是把 macOS 的 tkinter 的lib 複製一份到 目錄下。

改用「右鍵」去點選app 後,選擇「顯示套件內容」(Show Package Contents)的選項,點進去 Contents 目錄下的 Mac OS 目錄裡,去點2下執行 platypus 所產生的執行檔,或是直接執行 python 都是可以正常執行。

直接使用 python2 在 m1 的環境下執行,會顯示該程式版本太久,需要聯繫開發者,點下去「確定」的按鈕,會開啟網頁,顯示 python 2 在macOS 已經日薄西山:

Same issue (missing init.tcl) on my setup:

  • macOS 10.15.5, venv with Python 3.7.7 interpreter (includes TCL8.6), py2app 0.21
  • It turns out that TCL is not copied neither to venv nor to .app by py2app, so the generated .app is finding TCL in Python installation directory (/Library/Frameworks/Python.framework/Versions/3.7/lib/tcl8.6) on my setup.
    • however this is not available on the setups without Python installation -> error


When I’ve manually copied:

- /Library/Frameworks/Python.framework/Versions/3.7/lib/tcl8
- /Library/Frameworks/Python.framework/Versions/3.7/lib/tcl8.6
- /Library/Frameworks/Python.framework/Versions/3.7/lib/tk8.6


- path_to_venv/lib

py2app will take it from there and store it in the .app in this location:

- path_to_project/dist/

and from here it is found by the python code

Next steps

I see 2 main options how to automate it:

  1. In py2app setup file implement a check for the TCL availability in the venv structure and copy it from the system location if not available
  2. Implement it directly in py2app


Send py2app application to Mac without python



發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *