【解决】MacOS下 Python3.7 使用 pyinstaller 打包后执行报错 Failed to execute script pyi_rth__tkinter

Fix tcl/tk libs inclusion in tkinter with Python3.7 under MacOS

使用 Pyinstaller 打包时候报错 

3027 ERROR: Tcl/Tk improperly installed on this system.
(lyj_venv) ➜ liyongjiandeMBP.lan [/Users/liyongjian/lyj] pyinstaller --windowed --onefile --clean --noconfirm ServenDigitsDrawV2.py
77 INFO: PyInstaller: 3.4
77 INFO: Python: 3.7.3
84 INFO: Platform: Darwin-18.5.0-x86_64-i386-64bit
85 INFO: wrote /Users/liyongjian/lyj/ServenDigitsDrawV2.spec
88 INFO: UPX is not available.
89 INFO: Removing temporary files and cleaning cache in /Users/liyongjian/Library/Application Support/pyinstaller
96 INFO: Extending PYTHONPATH with paths
['/Users/liyongjian/lyj', '/Users/liyongjian/lyj']
96 INFO: checking Analysis
96 INFO: Building Analysis because Analysis-00.toc is non existent
96 INFO: Initializing module dependency graph...
97 INFO: Initializing module graph hooks...
99 INFO: Analyzing base_library.zip ...
2805 INFO: running Analysis Analysis-00.toc
2814 INFO: Caching module hooks...
2817 INFO: Analyzing /Users/liyongjian/lyj/ServenDigitsDrawV2.py
3015 INFO: Loading module hooks...
3015 INFO: Loading module hook "hook-_tkinter.py"...
3027 ERROR: Tcl/Tk improperly installed on this system.
3027 INFO: Loading module hook "hook-encodings.py"...
3086 INFO: Loading module hook "hook-xml.py"...
3281 INFO: Loading module hook "hook-pydoc.py"...
3292 INFO: Looking for ctypes DLLs
3292 INFO: Analyzing run-time hooks ...
3295 INFO: Including run-time hook 'pyi_rth__tkinter.py'
3303 INFO: Looking for dynamic libraries
3411 INFO: Looking for eggs
3411 INFO: Using Python library /Library/Frameworks/Python.framework/Versions/3.7/Python
3413 INFO: Warnings written to /Users/liyongjian/lyj/build/ServenDigitsDrawV2/warn-ServenDigitsDrawV2.txt
3439 INFO: Graph cross-reference written to /Users/liyongjian/lyj/build/ServenDigitsDrawV2/xref-ServenDigitsDrawV2.html
3446 INFO: checking PYZ
3446 INFO: Building PYZ because PYZ-00.toc is non existent
3447 INFO: Building PYZ (ZlibArchive) /Users/liyongjian/lyj/build/ServenDigitsDrawV2/PYZ-00.pyz
3756 INFO: Building PYZ (ZlibArchive) /Users/liyongjian/lyj/build/ServenDigitsDrawV2/PYZ-00.pyz completed successfully.
3760 INFO: checking PKG
3760 INFO: Building PKG because PKG-00.toc is non existent
3760 INFO: Building PKG (CArchive) PKG-00.pkg
6336 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
6339 INFO: Bootloader /Users/liyongjian/lyj/lyj_venv/lib/python3.7/site-packages/PyInstaller/bootloader/Darwin-64bit/runw
6339 INFO: checking EXE
6339 INFO: Building EXE because EXE-00.toc is non existent
6339 INFO: Building EXE from EXE-00.toc
6339 INFO: Appending archive to EXE /Users/liyongjian/lyj/dist/ServenDigitsDrawV2
6346 INFO: Fixing EXE for code signing /Users/liyongjian/lyj/dist/ServenDigitsDrawV2
6352 INFO: Building EXE from EXE-00.toc completed successfully.
6354 INFO: checking BUNDLE
6354 INFO: Building BUNDLE because BUNDLE-00.toc is non existent
6354 INFO: Building BUNDLE BUNDLE-00.toc
6366 INFO: moving BUNDLE data files to Resource directory

执行的时候报错

➜ liyongjiandeMBP.lan [/Users/liyongjian] /Users/liyongjian/lyj/dist/ServenDigitsDrawV2 ; exit;
Traceback (most recent call last):
File "PyInstaller/loader/rthooks/pyi_rth__tkinter.py", line 28, in <module>
FileNotFoundError: Tcl data directory "/var/folders/f9/6m090zhs6w55rmbmhkmpff440000gn/T/_MEITVlJln/tcl" not found.
[39503] Failed to execute script pyi_rth__tkinter

[进程已完成]

解决办法:

在文件中增加 

 and 'Python' not in path_to_tcl
PyInstaller/hooks/hook-_tkinter.py
@@ -180,7 +180,7 @@ def _find_tcl_tk(hook_api):
180
181   # _tkinter depends on Tcl/Tk compiled as frameworks.
182   path_to_tcl = bins[0][1]
    - if 'Library/Frameworks' in path_to_tcl:
183 + if 'Library/Frameworks' in path_to_tcl and 'Python' not in path_to_tcl:

 

参考链接:https://github.com/pyinstaller/pyinstaller/pull/3830
               https://stackoverflow.com/questions/51847801/pyinstaller-app-not-opening-on-mac

posted @ 2019-04-10 14:40  liyongjian5179  阅读(10112)  评论(0编辑  收藏  举报