我正在使用py2exe创建我的独立可执行文件,已经尝试过pyinstaller,cx_freeze甚至nuitka,但这些都不起作用。 问题是py2exe引发以下错误:ImportError:没有名为“ tkinter._fix”的模块
我用tkinter来构建我的应用程序。
我的安装文件如下:
from distutils.core import setup
import py2exe
setup(console=['BioRank.py'], options = {'py2exe':{'packages':['numpy','tkinter','pandas','xlwt']}})
我正在使用Windows10,python 3.4和py2exe 0.9.2.2
有人可以帮我吗?
答案 0 :(得分:0)
我最近在使用nuitka时遇到了同样的问题。我通过添加自己的逻辑来复制丢失的TK / TCL部分来解决了该问题:
import sys, os, subprocess, shutil
pscript = sys.argv[1]
pscript_n = pscript[:-3]
EXE = pscript_n + ".exe"
if not os.path.exists(pscript):
raise SystemExit("Python source '%s' does not exist!" % pscript)
tk = os.path.join(sys.exec_prefix,"tcl", "tk8.6")
tcl = os.path.join(sys.exec_prefix,"tcl", "tcl8.6")
if not os.path.exists(tk):
raise SystemExit("unexpected: '%s' does not exist!" % tk)
if not os.path.exists(tcl):
raise SystemExit("unexpected: '%s' does not exist!" % tcl)
dist_path = os.path.join("compiled", pscript_n + ".dist")
if os.path.exists(dist_path):
print("removing old binaries ...")
shutil.rmtree(dist_path, ignore_errors=True)
if not os.path.exists("compiled"):
print("creating 'compiled' sub dir ...")
os.mkdir("compiled")
os.mkdir(os.path.join("compiled", "lib"))
os.mkdir(os.path.join("compiled", "bin"))
tar_tk = os.path.join("compiled", "lib", "tk8.6")
tar_tcl = os.path.join("compiled", "lib", "tcl8.6")
shutil.copytree(tk, tar_tk)
shutil.copytree(tcl, tar_tcl)
print("'compiled' sub dir created")
print("Next messages are from Nuitka compilation.\n")
cmd = "python -m nuitka --portable --remove-output --output-dir=compiled " + pscript
subprocess.call(cmd)
copy_cmd = "xcopy /E/S/Y %s compiled\\bin" % dist_path
if os.path.exists(dist_path):
print("".ljust(100, "-"))
print("nuitka successful, now xcopying to compiled\\bin directory")
print("".ljust(100, "-"))
subprocess.call(copy_cmd)
print("".ljust(100, "-"))
print("'%s' should now be in '%s' and in 'compiled\\bin'\n" % (EXE, dist_path))
它的作用: 它查找并复制相关的TK和TCL库,并将它们与nuitka自身创建的库(称为scriptname.dist)一起共同放置在名为“ lib”的目录中。然后,我将.dist内容复制到“运行”目录中。 您可以为想要.exe的每个脚本重复此脚本。随着时间的推移,它们将进入“运行”目录,以形成您自己的EXE的库。