Python版本: 3.6包的最新版本
你好,我需要帮助我的安装,我有安装文件,但它不工作,我不知道为什么
import cx_Freeze
import sys
import matplotlib
base = None
if sys.platform =="win32":
base = "Win32GUI"
executables = [cx_Freeze.Executable("python.py", base=base,)]
cx_Freeze.setup(
name = "music-Client",
options = {"build_exe": {"packages":["tkinter","matplotlib","Pygame"]}},
version = "1",
description = "hello",
executables = executables
)当我尝试用cmd构建它时,这个很长的错误就出现了。
Traceback (most recent call last):
File "setup.py", line 17, in <module>
executables = executables
File "E:\Projekty\venv\lib\site-packages\cx_Freeze\dist.py", line 349, in setup
distutils.core.setup(**attrs)
File "E:\Python\Lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "E:\Python\Lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "E:\Python\Lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "E:\Python\Lib\distutils\command\build.py", line 135, in run
self.run_command(cmd_name)
File "E:\Python\Lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "E:\Python\Lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "E:\Projekty\venv\lib\site-packages\cx_Freeze\dist.py", line 219, in run
freezer.Freeze()
File "E:\Projekty\venv\lib\site-packages\cx_Freeze\freezer.py", line 616, in Freeze
self.finder = self._GetModuleFinder()
File "E:\Projekty\venv\lib\site-packages\cx_Freeze\freezer.py", line 342, in _GetModuleFinder
finder.IncludePackage(name)
File "E:\Projekty\venv\lib\site-packages\cx_Freeze\finder.py", line 659, in IncludePackage
module = self._ImportModule(name, deferredImports)
File "E:\Projekty\venv\lib\site-packages\cx_Freeze\finder.py", line 311, in _ImportModule
deferredImports, namespace = namespace)
File "E:\Projekty\venv\lib\site-packages\cx_Freeze\finder.py", line 404, in _InternalImportModule
parentModule, namespace)
File "E:\Projekty\venv\lib\site-packages\cx_Freeze\finder.py", line 417, in _LoadModule
namespace)
File "E:\Projekty\venv\lib\site-packages\cx_Freeze\finder.py", line 486, in _LoadPackage
self._LoadModule(name, fp, path, info, deferredImports, parent)
File "E:\Projekty\venv\lib\site-packages\cx_Freeze\finder.py", line 464, in _LoadModule
self._RunHook("load", module.name, module)
File "E:\Projekty\venv\lib\site-packages\cx_Freeze\finder.py", line 537, in _RunHook
method(self, *args)
File "E:\Projekty\venv\lib\site-packages\cx_Freeze\hooks.py", line 615, in load_tkinter
tclSourceDir = os.environ["TCL_LIBRARY"]
File "E:\Projekty\venv\lib\os.py", line 669, in __getitem__
raise KeyError(key) from None
KeyError: 'TCL_LIBRARY'我不知道怎么解决这个问题,有人能帮我吗?我真的需要帮助,谢谢你的回答
发布于 2018-01-24 01:10:27
您需要包含tkinter库。使用os.environ()方法可以很容易地做到这一点。
它应该是这样的:
import os
os.environ["TCL_LIBRARY"] = "<PathToPython>/Python36-32/tcl/tcl8.6"
os.environ["TK_LIBRARY"] = "<PathToPython>/Python36-32/tcl/tk8.6"在您的脚本中,它可能如下所示:
import cx_Freeze
import sys
import os
os.environ["TCL_LIBRARY"] = "<PathToPython>/Python36-32/tcl/tcl8.6"
os.environ["TK_LIBRARY"] = "<PathToPython>/Python36-32/tcl/tk8.6"
base = None
if sys.platform =="win32":
base = "Win32GUI"
executables = [cx_Freeze.Executable("python.py", base=base,)]
cx_Freeze.setup(
name = "music-Client",
options = {"build_exe": {"packages":["tkinter","matplotlib","Pygame"]}},
version = "1",
description = "hello",
executables = executables
)注意,我删除了import mathplotlib,因为这在安装脚本中不需要,通常会检测到依赖项。
如果这还不够:
通常还会返回另一个错误。这是缺少的运行时错误。您可以使用include_files方法包括运行时(如文档中所述)。我们可以将这一声明包括在这一行:
options = {"build_exe": {"packages":["tkinter","matplotlib","Pygame"]}},如下所示:
options = {"build_exe": {"packages":["tkinter","matplotlib","Pygame"], "include_files":["<PathToPython>/Python36-32/DLLs/tk86t.dll", "<PathToPython>/Python36-32/DLLs/tcl86t.dll"]}},https://stackoverflow.com/questions/48354778
复制相似问题