将 tkinter 转换为 exe 的 Py2exe 错误 - "模块"对象没有属性"tcldir"



我在使用 py2exe 将带有 tkinter 的 python3 脚本转换为 exe 时遇到问题。

没有tkinter,程序将成功转换为exe。

我尝试创建普通和捆绑的exe,但它每次都会引发以下异常:

running py2exe
Traceback (most recent call last):
File "setup_py2exe_assist.py", line 14, in <module>
'bundle_files': 1,
File "C:Python34libdistutilscore.py", line 148, in setup
dist.run_commands()
File "C:Python34libdistutilsdist.py", line 955, in run_commands
self.run_command(cmd)
File "C:Python34libdistutilsdist.py", line 974, in run_command
cmd_obj.run()
File "C:Python34libsite-packagespy2exedistutils_buildexe.py", line 188, in run
self._run()
File "C:Python34libsite-packagespy2exedistutils_buildexe.py", line 267, in _run
builder.analyze()
File "C:Python34libsite-packagespy2exeruntime.py", line 173, in analyze
target.analyze(mf)
File "C:Python34libsite-packagespy2exeruntime.py", line 74, in analyze
modulefinder.run_script(self.script)
File "C:Python34libsite-packagespy2exemf3.py", line 86, in run_script
self._scan_code(mod.__code__, mod)
File "C:Python34libsite-packagespy2exemf3.py", line 394, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "C:Python34libsite-packagespy2exemf3.py", line 138, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "C:Python34libsite-packagespy2exemf3.py", line 120, in import_hook
module = self._gcd_import(name)
File "C:Python34libsite-packagespy2exemf3.py", line 274, in _gcd_import
return self._find_and_load(name)
File "C:Python34libsite-packagespy2exemf3.py", line 341, in _find_and_load
self._load_module(loader, name)
File "C:Python34libsite-packagespy2exemf3.py", line 372, in _load_module
self._add_module(name, mod)
File "C:Python34libsite-packagespy2exedllfinder.py", line 209, in _add_module
self.hook(mod)
File "C:Python34libsite-packagespy2exedllfinder.py", line 206, in hook
mth(self, mod)
File "C:Python34libsite-packagespy2exehooks.py", line 259, in hook_tkinter
tcl_dir = os.path.normpath(os.path.join(fix.tcldir, ".."))
AttributeError: 'module' object has no attribute 'tcldir'

需要明确的是,我想包括tkinter。请帮助找出问题,因为我在任何地方都找不到这个问题的解决方案。顺便问一下,有人有和我一样的问题吗?

我正在使用python 3.6,我认为您也在做同样的事情。我也遇到了这个问题,并解决了pyinstaller,可以使用pip安装。这完全支持 3.6 和以前的版本,但我更喜欢的是--noconsole参数,它不显示标准 I/O 窗口(所以你只能得到你的tkinter窗口)

编辑: 抱歉,刚刚查看了文件路径,发现您正在使用python 3.4.这可能意味着我的回答无关紧要:'(

最新更新