Py2Exe TkInter:DLL加载失败

时间:2017-03-17 01:52:19

标签: python python-3.x tkinter py2exe

我使用py2exe来创建编译我的Python 3.4脚本。它在我编译的PC上运行正常(Windows 10 64位),但是当我尝试在没有安装Python的另一台PC上运行它(Windows 7 64位)时,我在日志中收到以下错误:

Traceback (most recent call last):
  File "PCSpeedDiagnostics.pyw", line 12, in <module>
  File "C:\Python34\lib\tkinter\__init__.py", line 36, in <module>
  File "C:\Python34\lib\tkinter\_fix.py", line 65, in <module>
  File "<loader>", line 10, in <module>
  File "<loader>", line 8, in __load
ImportError: (DLL load failed: The specified module could not be found.) 'C:\\Users\\[MY NAME]\\Downloads\\dist\\_tkinter.pyd'

_tkinter.pyd文件实际上包含在显然无法找到的目录中。

以下是我的setup.py文件:

from distutils.core import setup
import py2exe, tkinter

setup(windows=['PCSpeedDiagnostics.pyw'],
    name="PC Speed Diagnostics Tool",
    data_files = [('', ['banner.png', 'blank.png', 'dialog_apply.png',
                        'gnome_application_x_executable.png', 'gnome_dialog_error.png',
                        'gnome_document_send.png', 'gnome_document_send_error.png',
                        'gnome_network_offline.png', 'gnome_network_transmit_receive.png',
                        'gnome_network_wireless.png', 'gnome_system_run.png',
                        'iperf3.exe'])],
    options = {
        'py2exe': {
            'bundle_files': 3,
            'optimize': 2,
            'includes': ['tkinter'],
        }
    },
)

有谁知道我做错了什么?

1 个答案:

答案 0 :(得分:0)

感谢https://stackoverflow.com/a/14566647/963265,我现在有了答案。

这是我的新setup.py文件:

from distutils.core import setup
import py2exe, tkinter

setup(windows=['PCSpeedDiagnostics.pyw'],
    name="PC Speed Diagnostics Tool",
    data_files = [('', ['banner.png', 'blank.png', 'dialog_apply.png',
                        'gnome_application_x_executable.png', 'gnome_dialog_error.png',
                        'gnome_document_send.png', 'gnome_document_send_error.png',
                        'gnome_network_offline.png', 'gnome_network_transmit_receive.png',
                        'gnome_network_wireless.png', 'gnome_system_run.png',
                        'tcl86.dll', 'tk86.dll', 'iperf3.exe'])],
    options = {
        'py2exe': {
            'bundle_files': 3,
            'optimize': 1,
            'includes': ['tkinter'],
            'dll_excludes': ['tcl86.dll', 'tk86.dll'],
        }
    },
)

我已将tcl86.dll和tk86.dll复制到与exe相同的目录中。