CX Freeze No mpl_toolkits Module found error and Pyinstaller Cannot open self .exe 当我将其复制到除 C 盘以外的其他位置时
CX Freeze No mpl_toolkits Module found error and Pyinstaller Cannot open self .exe when I copy it to other location other than C drive
当我通过以下命令制作我的exe文件时
pyinstaller --hidden-import=pkg_resources.py2_warn --onefile example.py
它工作正常并将我的 python 脚本转换为 .exe 但是当我将该文件复制到其他位置时它不起作用并说无法打开自我错误,然后我尝试了以下所有尝试失败
我已经将我的.exe中需要的所有图标复制到同一个文件夹中
尝试 1)
pyinstaller --debug --onefile --noupx test.py#same error
尝试 2)
错误(试图复制错误但无法复制,因为控制台停留了几分之一秒并自动关闭)
cannotopenself (then it gives the location where I copied my newly made .exe file)
然后我尝试使用 CX_FREEZE 然后它又说没有找到 tkinter 模块错误
我已将所有必需的 DLL 文件包含在我的脚本所在的主文件中,但它仍然给出 tkinter not found 错误,已尝试以下方法
我已经包含了 tkinter 但仍然出现此错误
这是我的setup.py文件
from cx_Freeze import setup, Executable
# imported tkinter here also
from tkinter import *
import sys
import os.path
import os.path
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], 'includes':["tkinter"],'include_files':['tk86t.dll','tcl86t.dll','text.ico','viewer.ico']}
# included tkinter also
# 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 = "MINE",
version = "0.1",
description = "MY FILE",
options = {"build_exe": build_exe_options},
executables = [Executable("EXAMPLE.py", base=base)])
以下是 CX FREEZE 图像的错误
这是 PYINSTALLER 的图像错误
现在我更改了我的 Setup.py 脚本,并将文件夹名称从 Tkinter 更改为 tkinter 现在它说
from cx_Freeze import setup, Executable
from tkinter import *
import sys
import os.path
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os","numpy","time","optparse","linecache","pandas",
"matplotlib","PIL","tk"],'include_files':['tcl86t.dll','tk86t.dll','graphs.ico','viewer.ico']}
# 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 = "My file",
version = "0.1",
description = "MY FILE ",
options = {"build_exe": build_exe_options},
executables = [Executable("My_file.py", base=base)])
现在是
这是我们需要遵循的方法 cx_freeze
a)首先从安装了 python 的 python 文件夹中复制 tk86t.dll,tcl86t.dll,主要是在 app_data 的本地文件夹 中,将其复制到 你有 setup.py 文件的地方
b)然后在pycharm终端输入
安装通过后
pip install cx_freeze
c)您需要在 setup.py 文件的构建选项中安装 main.py 文件中包含的所有库,然后键入
python setup.py build
在 pycharm 终端
下面是 tan_an 在评论中建议的 setup.py 文件,我请求他但他没有 post 他的回答所以为了帮助社区我正在这样做
from cx_Freeze import setup, Executable
from tkinter import *
import sys
import os.path
import mpl_toolkits
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os","numpy","time","optparse","linecache","pandas",
"matplotlib","PIL","tk"],"namespace_packages":['mpl_toolkits'],'include_files':['tcl86t.dll','tk86t.dll']}
# 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 = "Your file",
version = "0.1",
description = "your file",
options = {"build_exe": build_exe_options},
executables = [Executable("yourfile.py", base=base)])
现在构建后转到构建文件夹,在 win32 文件夹中转到 lib,然后将 Tkinter 文件夹的名称更改为 tkinter
现在运行你的申请
当我通过以下命令制作我的exe文件时
pyinstaller --hidden-import=pkg_resources.py2_warn --onefile example.py
它工作正常并将我的 python 脚本转换为 .exe 但是当我将该文件复制到其他位置时它不起作用并说无法打开自我错误,然后我尝试了以下所有尝试失败
我已经将我的.exe中需要的所有图标复制到同一个文件夹中
尝试 1)
pyinstaller --debug --onefile --noupx test.py#same error
尝试 2)
错误(试图复制错误但无法复制,因为控制台停留了几分之一秒并自动关闭)
cannotopenself (then it gives the location where I copied my newly made .exe file)
然后我尝试使用 CX_FREEZE 然后它又说没有找到 tkinter 模块错误
我已将所有必需的 DLL 文件包含在我的脚本所在的主文件中,但它仍然给出 tkinter not found 错误,已尝试以下方法
我已经包含了 tkinter 但仍然出现此错误
这是我的setup.py文件
from cx_Freeze import setup, Executable
# imported tkinter here also
from tkinter import *
import sys
import os.path
import os.path
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], 'includes':["tkinter"],'include_files':['tk86t.dll','tcl86t.dll','text.ico','viewer.ico']}
# included tkinter also
# 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 = "MINE",
version = "0.1",
description = "MY FILE",
options = {"build_exe": build_exe_options},
executables = [Executable("EXAMPLE.py", base=base)])
以下是 CX FREEZE 图像的错误
这是 PYINSTALLER 的图像错误
现在我更改了我的 Setup.py 脚本,并将文件夹名称从 Tkinter 更改为 tkinter 现在它说
from cx_Freeze import setup, Executable
from tkinter import *
import sys
import os.path
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os","numpy","time","optparse","linecache","pandas",
"matplotlib","PIL","tk"],'include_files':['tcl86t.dll','tk86t.dll','graphs.ico','viewer.ico']}
# 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 = "My file",
version = "0.1",
description = "MY FILE ",
options = {"build_exe": build_exe_options},
executables = [Executable("My_file.py", base=base)])
现在是
这是我们需要遵循的方法 cx_freeze
a)首先从安装了 python 的 python 文件夹中复制 tk86t.dll,tcl86t.dll,主要是在 app_data 的本地文件夹 中,将其复制到 你有 setup.py 文件的地方
b)然后在pycharm终端输入
安装通过后
pip install cx_freeze
c)您需要在 setup.py 文件的构建选项中安装 main.py 文件中包含的所有库,然后键入
python setup.py build
在 pycharm 终端
下面是 tan_an 在评论中建议的 setup.py 文件,我请求他但他没有 post 他的回答所以为了帮助社区我正在这样做
from cx_Freeze import setup, Executable
from tkinter import *
import sys
import os.path
import mpl_toolkits
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os","numpy","time","optparse","linecache","pandas",
"matplotlib","PIL","tk"],"namespace_packages":['mpl_toolkits'],'include_files':['tcl86t.dll','tk86t.dll']}
# 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 = "Your file",
version = "0.1",
description = "your file",
options = {"build_exe": build_exe_options},
executables = [Executable("yourfile.py", base=base)])
现在构建后转到构建文件夹,在 win32 文件夹中转到 lib,然后将 Tkinter 文件夹的名称更改为 tkinter 现在运行你的申请