cx_Freeze ImportError:使用Tkinter时没有名为FileDialog的模块错误

时间:2018-07-02 12:45:38

标签: python tkinter cx-freeze

我遇到了通过 cx_Freeze 创建可执行文件的问题,已经花了很多时间来寻找解决方案,但是很遗憾,没有结果。希望有人有类似的东西。

我的 setup.py 如下所示:

import sys
import matplotlib
from cx_Freeze import setup, Executable
import Tkinter
import tkFileDialog as FileDialog


packages = ['django', 'HTMLParser', 'Cookie', 'Tkinter', 'tkFileDialog']
additionalMods = ['numpy.core._methods', 'numpy.lib.format', 'matplotlib.backends.backend_tkagg']

buildOptions = dict(
        path = sys.path,
        include_files = [(matplotlib.get_data_path(), "mpl-data")],
        includes = ['django_settings', 'django.template.defaulttags', 'django.template.defaultfilters'] + additionalMods,
        packages = packages,
        excludes = ['collections.abc'],)

def execSpec(name):
    return Executable(name + '.py', targetName = name + '.exe',
            base = "Console")

setup(
        name = 'Packaged', 
        version = '1.0',
        description = 'Test build', 
        options = dict(build_exe = buildOptions), 
        executables = map(execSpec, ['packaged',])

冻结过程很好,但是当我尝试运行冻结程序时,总是出现相同的错误:

  File "C:\Python27-x64\lib\site-packages\matplotlib\backends\__init__.py", line  32, in pylab_setup
    globals(),locals(),[backend_name],0)   File "C:\Python27-x64\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 7, in <module>
    from six.moves import tkinter_filedialog as FileDialog   File "C:\Python27-x64\lib\site-packages\six.py", line 203, in load_module
    mod = mod._resolve()   File "C:\Python27-x64\lib\site-packages\six.py", line 115, in _resolve
    return _import_module(self.mod)   File "C:\Python27-x64\lib\site-packages\six.py", line 82, in _import_module
    __import__(name) ImportError: No module named FileDialog

我已经将TkintertkFileDialog添加到程序包选项中,并将import tkFileDialog as FileDialog放入冻结的脚本中,但这无济于事。

我正在使用Python 2.7.3和cx_Freeze 5.1.1。我也可以导入Tkinter和tkFileDialog而不会出现任何显式错误:

>>> import Tkinter
>>> import tkFileDialog
>>> 

谢谢!

0 个答案:

没有答案