运行cx_Freeze制作的程序时出现ImportError

时间:2019-05-23 19:53:07

标签: python cx-freeze

尝试运行cx_Freeze从.py脚本创建.exe文件时出现错误。

错误:

enter image description here

cx_Freeze版本:6.0b1

我的设置文件:

import sys,os
from cx_Freeze import setup, Executable

os.environ['TCL_LIBRARY'] = r'C:\Users\drees\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\drees\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6'
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
base = None

if sys.platform == 'win32':
    base = "Win32GUI"

if sys.platform == 'win64':
    base = "Win64GUI"

build_exe_options = {"packages": ['numpy.core._methods', 'numpy.lib.format',"matplotlib.backends.backend_tkagg"],
"include_files": [(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll')),(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'))]}

setup(
    name = "ZVI App",
    version = "0.0",
    description = "All-in-one application",
    author = "David Rees",
    author_email = "drees@zahroofvalves.com",
    options = {"build_exe": build_exe_options},
    executables = [Executable("ZVIApp.py", base = base,icon = "ZVI.ico")]

该如何解决?我已经使用了PyInstaller,并且运行良好,我只是想看看cx_Freeze是否会使我的程序启动更快,因为使用PyInstaller花费了10秒钟。解释器大约需要3秒钟来运行代码。

1 个答案:

答案 0 :(得分:0)

我看到2个潜在问题:

  1. 尝试安装最新版本的xlwings。在其他环境中针对xlwings报告的issue with the same error message

  2. 您可能会在冻结应用程序的操作系统,所使用的python版本以及运行冻结的应用程序的操作系统之间混合使用32位和64位。请参阅我对{{3}的回答},以了解可能的工作配置。