1

我正在使用cx_freeze开发版本(如此处所建议也尝试了最新的稳定版 1.3.1),我尝试从导入 numpy 和 Enthought Canopy 发行版的文件构建 Windows 可执行文件。这是文件test.py

import numpy as np

def f(x):

    y = np.linspace(0,x,1000)
    return y

if __name__ == '__main__':
    print f(5)

这是 setup.py 文件:

import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}

# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
    base = None

setup(  name = "foo",
        version = "0.1",
        description = "My GUI application!",
        options = {"build_exe": build_exe_options},
        executables = [Executable("test.py", base=base)])

这是我运行exe时遇到的错误:

Traceback (most recent call last):
  File "C:\Users\Zah\AppData\Local\Enthought\Canopy32\User\lib\site-packages\cx_
freeze-4.3.1-py2.7-win32.egg\cx_Freeze\initscripts\Console.py", line 27, in <mod
ule>
    exec code in m.__dict__
  File "test.py", line 7, in <module>
  File "C:\Users\Zah\AppData\Local\Enthought\Canopy32\User\lib\site-packages\num
py\__init__.py", line 143, in <module>
    import add_newdocs
  File "C:\Users\Zah\AppData\Local\Enthought\Canopy32\User\lib\site-packages\num
py\add_newdocs.py", line 9, in <module>
    from numpy.lib import add_newdoc
  File "C:\Users\Zah\AppData\Local\Enthought\Canopy32\User\lib\site-packages\num
py\lib\__init__.py", line 13, in <module>
    from polynomial import *
  File "C:\Users\Zah\AppData\Local\Enthought\Canopy32\User\lib\site-packages\num
py\lib\polynomial.py", line 17, in <module>
    from numpy.linalg import eigvals, lstsq, inv
  File "C:\Users\Zah\AppData\Local\Enthought\Canopy32\User\lib\site-packages\num
py\linalg\__init__.py", line 48, in <module>
    from linalg import *
  File "C:\Users\Zah\AppData\Local\Enthought\Canopy32\User\lib\site-packages\num
py\linalg\linalg.py", line 23, in <module>
    from numpy.linalg import lapack_lite
  File "ExtensionLoader_numpy_linalg_lapack_lite.py", line 22, in <module>
  File "ExtensionLoader_numpy_linalg_lapack_lite.py", line 14, in __bootstrap__
ImportError: DLL load failed: No se puede encontrar el m¾dulo especificado.

我注意到构建目录中有一个numpy.linalg.lapack_lite.pyd文件。

4

1 回答 1

0

在您的 Python 安装目录中,转到 Scripts 目录(即 C:/Python27/Scripts)。在此文件夹中,您应该找到两个 DLL 文件:

  1. mk2_core.dll
  2. mk2iomp5md.dll

编辑您的 cxFreeze 构建例程,以便将这两个文件复制到与您的可执行文件相同的目录(您的构建目录)。之后,尝试运行 exe,这应该可以解决问题(无论如何它都对我有用)。


我是怎么想出来的?你说你注意到了 numpy.linalg.lapack_lite.p.yd 文件。我所做的是使用名为 DependencyWalker(网站)的工具打开此文件。该程序分析文件具有的所有 DLL 依赖项。经过分析,它告诉我这两个 DLL 文件丢失了。

我真的希望这会有所帮助,我知道这些事情是多么令人沮丧!

于 2014-12-10T15:25:06.200 回答