没有名为 tkinter 的模块,使用 cx-freeze 时,即使我指定了模块的路径
no module named tkinter, when using cx-freeze, even I specified the path of the module
我有一个 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: No module named tkinter"。我把包的路径放在了os.environ,但是我还是不明白为什么它不识别它。如果有人知道如何解决这个问题,我将不胜感激。
我正在使用 Windows,并且我在主 python 脚本中使用了 "import tkinter"。主python fyle 使用命令python mainprog.py 正常执行,但问题出在构建命令创建的.exe 文件中。
Excludes 表示不包含包。我建议您从安装脚本中的 excludes = ['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)]
)
from cx_Freeze import setup, Executable
import tkinter
import sys
import os
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "includes": ["tkinter"],"include_files": ["ico.png"]}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(name="merge",
version="0.1",
description="My GUI application!",
options={"build_exe": build_exe_options},
executables=[Executable("merge.py", base=base)])
有类似的问题。 setup.py 的这种格式帮我解决了。
经过大量研究并按照说明进行操作后,没有任何效果。我检查我已经在 lib 中有 tcl8.6 和 tk8.6 文件,但我注意到 Tkinter 文件夹以大写字母开头,它寻找 "tkinter",所以我将 "T" 更改为"t",令人惊讶的是,这似乎很实用。
我有一个 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: No module named tkinter"。我把包的路径放在了os.environ,但是我还是不明白为什么它不识别它。如果有人知道如何解决这个问题,我将不胜感激。
我正在使用 Windows,并且我在主 python 脚本中使用了 "import tkinter"。主python fyle 使用命令python mainprog.py 正常执行,但问题出在构建命令创建的.exe 文件中。
Excludes 表示不包含包。我建议您从安装脚本中的 excludes = ['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)]
)
from cx_Freeze import setup, Executable
import tkinter
import sys
import os
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "includes": ["tkinter"],"include_files": ["ico.png"]}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(name="merge",
version="0.1",
description="My GUI application!",
options={"build_exe": build_exe_options},
executables=[Executable("merge.py", base=base)])
有类似的问题。 setup.py 的这种格式帮我解决了。
经过大量研究并按照说明进行操作后,没有任何效果。我检查我已经在 lib 中有 tcl8.6 和 tk8.6 文件,但我注意到 Tkinter 文件夹以大写字母开头,它寻找 "tkinter",所以我将 "T" 更改为"t",令人惊讶的是,这似乎很实用。