pyinstaller无法使用tkin

2024-04-30 04:57:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用pyinstaller让一个在其他方面正常工作的Python程序冻结为单个文件的可执行文件,但是我一直遇到与pyinstaller相关的相同错误。我已经把程序降到了绝对最小值以引起错误,即导入tkinter。在

测试程序:

import tkinter as tk

终端命令:

^{pr2}$

输出:

1625 INFO: PyInstaller: 3.4.dev0+ab8fd9753
1625 INFO: Python: 3.6.3
1647 INFO: Platform: Darwin-17.3.0-x86_64-i386-64bit
1648 INFO: wrote /Users/jacob/test/test.spec
1653 INFO: UPX is not available.
1654 INFO: Removing temporary files and cleaning cache in /Users/jacob/Library/Application Support/pyinstaller
1655 INFO: Extending PYTHONPATH with paths
['/Users/jacob/test', '/Users/jacob/test']
1656 INFO: checking Analysis
1656 INFO: Building Analysis because out00-Analysis.toc is non existent
1656 INFO: Initializing module dependency graph...
1658 INFO: Initializing module graph hooks...
1666 INFO: Analyzing base_library.zip ...
5415 INFO: Analyzing hidden import 'tkinter'
5568 INFO: running Analysis out00-Analysis.toc
5595 INFO: Caching module hooks...
5600 INFO: Analyzing /Users/jacob/test/test.py
5604 INFO: Loading module hooks...
5604 INFO: Loading module hook "hook-_tkinter.py"...
5623 INFO: checking Tree
5624 INFO: Building Tree because out00-Tree.toc is non existent
5624 INFO: Building Tree out00-Tree.toc
5704 INFO: checking Tree
5704 INFO: Building Tree because out01-Tree.toc is non existent
5704 INFO: Building Tree out01-Tree.toc
5746 INFO: Loading module hook "hook-encodings.py"...
5840 INFO: Loading module hook "hook-xml.py"...
6143 INFO: Loading module hook "hook-pydoc.py"...
6157 INFO: Looking for ctypes DLLs
6157 INFO: Analyzing run-time hooks ...
6159 INFO: Including run-time hook 'pyi_rth__tkinter.py'
6168 INFO: Looking for dynamic libraries
6453 INFO: Looking for eggs
6453 INFO: Using Python library /Library/Frameworks/Python.framework/Versions/3.6/Python
6456 INFO: Warnings written to /Users/jacob/test/build/test/warntest.txt
6483 INFO: Graph cross-reference written to /Users/jacob/test/build/test/xref-test.html
6507 INFO: checking PYZ
6507 INFO: Building PYZ because out00-PYZ.toc is non existent
6508 INFO: Building PYZ (ZlibArchive) /Users/jacob/test/build/test/out00-PYZ.pyz
6846 INFO: Building PYZ (ZlibArchive) /Users/jacob/test/build/test/out00-PYZ.pyz completed successfully.
6851 INFO: checking PKG
6851 INFO: Building PKG because out00-PKG.toc is non existent
6851 INFO: Building PKG (CArchive) out00-PKG.pkg
6874 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.
6877 INFO: Bootloader /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyInstaller/bootloader/Darwin-64bit/run
6877 INFO: checking EXE
6877 INFO: Building EXE because out00-EXE.toc is non existent
6877 INFO: Building EXE from out00-EXE.toc
6883 INFO: appending archive to EXE /Users/jacob/test/build/test/test
6888 INFO: Fixing EXE for code signing /Users/jacob/test/build/test/test
6894 INFO: Building EXE from out00-EXE.toc completed successfully.
6897 INFO: checking COLLECT
6897 INFO: Building COLLECT because out00-COLLECT.toc is non existent
6897 INFO: Building COLLECT out00-COLLECT.toc
7923 WARNING: failed to copy flags of /System/Library/Frameworks/Tcl.framework/Versions/8.5/Resources/Scripts/msgs/da.msg
7925 WARNING: failed to copy flags of /System/Library/Frameworks/Tcl.framework/Versions/8.5/Resources/Scripts/msgs/lv.msg
7927 WARNING: failed to copy flags of /System/Library/Frameworks/Tcl.framework/Versions/8.5/Resources/Scripts/msgs/kl.msg
7928 WARNING: failed to copy flags of /System/Library/Frameworks/Tk.framework/Versions/8.5/Resources/Scripts/comdlg.tcl
7930 WARNING: failed to copy flags of /System/Library/Frameworks/Tcl.framework/Versions/8.5/Resources/Scripts/msgs/gv_gb.msg
7932 WARNING: failed to copy flags of /System/Library/Frameworks/Tk.framework/Versions/8.5/Resources/Scripts/text.tcl

     <snipped 298 very similar lines>

8423 INFO: Building COLLECT out00-COLLECT.toc completed successfully.

运行可执行文件时:

Last login: Sun Dec 17 09:39:40 on ttys001
Jacobs-MacBook-Pro:~ jacob$ /Users/jacob/test/dist/test/test ; exit;
Traceback (most recent call last):
  File "test.py", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 631, in exec_module
    exec(bytecode, module.__dict__)
  File "tkinter/__init__.py", line 36, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 714, in load_module
    module = loader.load_module(fullname)
ImportError: dlopen(/Users/jacob/test/dist/test/_tkinter.so, 2): Library not loaded: @loader_path/Tcl
  Referenced from: /Users/jacob/test/dist/test/_tkinter.so
  Reason: no suitable image found.  Did find:
  /Users/jacob/test/dist/test/Tcl: not a file
  /Users/jacob/test/dist/test/Tcl: stat() failed with errno=25
  /Users/jacob/test/dist/test/Tcl: not a file
  /Users/jacob/test/dist/test/Tcl: stat() failed with errno=25
[731] Failed to execute script test
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[Process completed]

我如何使用tkinter获得一个可以正常工作的Python程序,使用pyinstaller冻结为一个文件可执行文件?在

更新:更新了输出和运行时错误,因为我最后得到的错误与我想问的不同。在


Tags: topytestinfotreelibraryframeworkversions
2条回答

我也遇到了同样的问题,但使用Python2.7。我通过从MacPorts安装py27-pyinstaller来解决这个问题。在

原来它与macOS上Tcl/Tk的路径有关。我找到了一个解决方法,包括编译我自己版本的Pyinstaller,修复错误,但除了macOS之外,对所有东西都破坏Pyinstaller。在

相关问题 更多 >