打开 cx_freeze 构建的 exe 文件时出错

Posted

技术标签:

【中文标题】打开 cx_freeze 构建的 exe 文件时出错【英文标题】:Error while opening the exe file built by cx_freeze 【发布时间】:2015-02-16 15:29:26 【问题描述】:

我使用 PyQt5、matplotlib、numpy、scipy、nmrglue 编写了一个程序,并设法使用 cx_freeze 将其构建为 exe 文件。

这是我的 setup.py:

from cx_Freeze import setup, Executable

setup(name= 'NmrAnalysis',
      version = '1.0',
      description = 'Analysis System by iceorange',
      executables = [Executable('MainWindow.py')])

当我执行MainWindow.exe时,它说:

E:\PycharmProjects\NmrAnalysis\build\exe.win-amd64-3.4>MainWindow.exe > ../out.txt
Traceback (most recent call last):
  File "D:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
    exec(code, m.__dict__)
  File "MainWindow.py", line 5, in <module>
  File "X:\Python34\lib\importlib\_bootstrap.py", line 2237, in _find_and_load
  File "X:\Python34\lib\importlib\_bootstrap.py", line 2226, in _find_and_load_unlocked
  File "X:\Python34\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked
  File "X:\Python34\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible
  File "E:\PycharmProjects\NmrAnalysis\nmr_analysis.py", line 8, in <module>
    import nmrglue as ng
  File "X:\Python34\lib\importlib\_bootstrap.py", line 2237, in _find_and_load
  File "X:\Python34\lib\importlib\_bootstrap.py", line 2226, in _find_and_load_unlocked
  File "X:\Python34\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked
  File "X:\Python34\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible
  File "D:\Python34\lib\site-packages\nmrglue\__init__.py", line 1, in <module>
    from .fileio import *
  File "X:\Python34\lib\importlib\_bootstrap.py", line 2237, in _find_and_load
  File "X:\Python34\lib\importlib\_bootstrap.py", line 2226, in _find_and_load_unlocked
  File "X:\Python34\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked
  File "X:\Python34\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible
  File "D:\Python34\lib\site-packages\nmrglue\fileio\__init__.py", line 1, in <module>
    from . import bruker
  File "X:\Python34\lib\importlib\_bootstrap.py", line 2284, in _handle_fromlist
  File "X:\Python34\lib\importlib\_bootstrap.py", line 321, in _call_with_frames_removed
  File "X:\Python34\lib\importlib\_bootstrap.py", line 2237, in _find_and_load
  File "X:\Python34\lib\importlib\_bootstrap.py", line 2226, in _find_and_load_unlocked
  File "X:\Python34\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked
  File "X:\Python34\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible
  File "D:\Python34\lib\site-packages\nmrglue\fileio\bruker.py", line 37, in <module>
    from ..process import proc_base
  File "X:\Python34\lib\importlib\_bootstrap.py", line 2237, in _find_and_load
  File "X:\Python34\lib\importlib\_bootstrap.py", line 2226, in _find_and_load_unlocked
  File "X:\Python34\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked
  File "X:\Python34\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible
  File "D:\Python34\lib\site-packages\nmrglue\process\__init__.py", line 1, in <module>
    from . import proc_base
  File "X:\Python34\lib\importlib\_bootstrap.py", line 2284, in _handle_fromlist
  File "X:\Python34\lib\importlib\_bootstrap.py", line 321, in _call_with_frames_removed
  File "X:\Python34\lib\importlib\_bootstrap.py", line 2237, in _find_and_load
  File "X:\Python34\lib\importlib\_bootstrap.py", line 2226, in _find_and_load_unlocked
  File "X:\Python34\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked
  File "X:\Python34\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible
  File "D:\Python34\lib\site-packages\nmrglue\process\proc_base.py", line 11, in <module>
    import scipy.signal
  File "X:\Python34\lib\importlib\_bootstrap.py", line 2237, in _find_and_load
  File "X:\Python34\lib\importlib\_bootstrap.py", line 2226, in _find_and_load_unlocked
  File "X:\Python34\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked
  File "X:\Python34\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible
  File "D:\Python34\lib\site-packages\scipy\signal\__init__.py", line 264, in <module>
    from .bsplines import *
  File "X:\Python34\lib\importlib\_bootstrap.py", line 2237, in _find_and_load
  File "X:\Python34\lib\importlib\_bootstrap.py", line 2226, in _find_and_load_unlocked
  File "X:\Python34\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked
  File "X:\Python34\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible
  File "D:\Python34\lib\site-packages\scipy\signal\bsplines.py", line 4, in <module>
    import scipy.special
  File "X:\Python34\lib\importlib\_bootstrap.py", line 2237, in _find_and_load
  File "X:\Python34\lib\importlib\_bootstrap.py", line 2226, in _find_and_load_unlocked
  File "X:\Python34\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked
  File "X:\Python34\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible
  File "D:\Python34\lib\site-packages\scipy\special\__init__.py", line 586, in <module>
    from ._ufuncs import *
  File "X:\Python34\lib\importlib\_bootstrap.py", line 2237, in _find_and_load
  File "X:\Python34\lib\importlib\_bootstrap.py", line 2226, in _find_and_load_unlocked
  File "X:\Python34\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked
  File "X:\Python34\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible
  File "ExtensionLoader_scipy_special__ufuncs.py", line 22, in <module>
  File "ExtensionLoader_scipy_special__ufuncs.py", line 14, in __bootstrap__
ImportError: DLL load failed: The specified module could not be found.

当我在 Dependency Walker 中运行它时,它会说: 如何解决这个问题呢? 非常感谢!

【问题讨论】:

【参考方案1】:

我终于成功让它工作了。

我在这里写了一个维基笔记: https://github.com/lianxiangru/NMR-Analysis-UI/wiki/Notes

Py2exe 也可以使用类似的程序。

【讨论】:

感谢您花时间记录您的发现。

以上是关于打开 cx_freeze 构建的 exe 文件时出错的主要内容,如果未能解决你的问题,请参考以下文章

在 PyQt 应用程序上使用 cx_freeze 时出现语法错误

cx_Freeze 没有名为“Tkinter”的模块

cx_freeze 将项目构建为 .exe 文件,出现 numpy 导入错误

使用 cx_Freeze 从 .py 构建一个 .exe 文件

将 .py 转换为 .exe 时出现 cx_Freeze 错误

使用 cx_freeze 转换为 *.exe 时出现 SSL 异常