python - 没有名为 tkinter 的模块,当使用 cx-freeze 时,即使我指定了模块的路径

标签 python cx-freeze

我有一个 python 脚本,我正在尝试使用 cx-freeze 使其可执行。这是我的 script.py 文件

 from cx_Freeze import setup,Executable
 import tkinter
 import sys
 import os

 os.environ['TCL_LIBRARY'] = "C:\\Users\\Admin\\Anaconda3\\tcl\\tcl8.6"
 os.environ['TCL_LIBRARY'] = "C:\\Users\\Admin\\Anaconda3\\tcl\\tk8.6"

 includes = []
 excludes = ['tkinter']
 packages = []
 base = "Win32GUI"
 setup(
     name = 'myapp',version = '0.1',description = 'app',author = 'user',
     options = {'build_exe': {'excludes':excludes,'packages':packages}}, 
     executables = [Executable('emetor1.py')]
 )

使用“python script.py build”执行时,将使用 .exe 文件创建构建文件夹。但是当我执行 .exe 文件时,它给出“ModuleNotFoundError:没有名为 tkinter 的模块”。我把包的路径放在了 os.environ 上,但我仍然不明白为什么它不识别它。如果有人知道如何解决这个问题,我将非常感激。

我使用的是 Windows,并且在我的主 Python 脚本中使用了“import tkinter”。主 python fyle 使用命令和 python mainprog.py 正常执行,但问题出在通过 build 命令创建时的 .exe 文件中。

最佳答案

排除表示不包含该包。我建议您从安装脚本中的 excepts = ['tkinter'] 中删除 'tkinter'。

编辑:尝试此设置脚本:

 from cx_Freeze import setup,Executable
 import sys
 import os

 os.environ['TCL_LIBRARY'] = r'C:\Users\Admin\Anaconda3\tcl\tcl8.6'
 os.environ['TK_LIBRARY'] = r'C:\Users\Admin\Anaconda3\tcl\tk8.6'

 includes = []
 include_files = [r"C:\Users\Admin\Anaconda3\DLLs\tcl86t.dll",
             r"C:\Users\Admin\Anaconda3\DLLs\tk86t.dll"]
 packages = []
 base = "Win32GUI"
 setup(
     name = 'myapp',version = '0.1',description = 'app',author = 'user',
     options = {'build_exe': {'includes':includes, 'include-files':include_files,'packages':packages}}, 
     executables = [Executable('emetor1.py', base=base)]
 )

关于python - 没有名为 tkinter 的模块,当使用 cx-freeze 时,即使我指定了模块的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45096619/

相关文章:

python - InnoSetup 后出现 cx_freeze fatal error

python - IPython 名称错误 : name 'pkg_resources' is not defined

python - Web 应用程序中的身份验证

python - 使用 gevents Wsgi 服务器在一个进程中多次启动和停止 Flask 应用程序

python - Psycopg2 数据库连接在丢失的网络连接上挂起

python - 将整数写入文件

python - 使用 cx_freeze : can I generate all apps from one platform? 在 Mac、Linux 和 Windows 上分发 python

python - 如何使用 cx_Freeze bundle 含 SQLObject 的应用程序

python - cx_freeze exe无限时间运行而不停止

python - 打包的 python .app 文件崩溃,但打包的 python .sh 文件工作正常