Scipy和CX_freeze - 导入scipy时出错:你在scipy源目录中导入时无法导入scipy

Pra*_*xis 7 scipy cx-freeze

我在使用cx_freeze和scipy时编译exe时遇到了麻烦.特别是,我的脚本使用

from scipy.interpolate import griddata
Run Code Online (Sandbox Code Playgroud)

构建过程似乎成功完成,但是当我尝试运行已编译的exe时,我收到以下消息.

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
    exec(code, m.__dict__)
  File "gis_helper.py", line 13, in <module>
  File "C:\Python27\lib\site-packages\scipy\__init__.py", line 103, in <module>
    raise ImportError(msg)
ImportError: Error importing scipy: you cannot import scipy while
        being in scipy source directory; please exit the scipy source
        tree first, and relaunch your python intepreter.
Run Code Online (Sandbox Code Playgroud)

在查看scipy\_init__.py文件后,有以下内容:

if __SCIPY_SETUP__:
    import sys as _sys
    _sys.stderr.write('Running from scipy source directory.\n')
    del _sys
else:
    try:
        from scipy.__config__ import show as show_config
    except ImportError:
        msg = """Error importing scipy: you cannot import scipy while
        being in scipy source directory; please exit the scipy source
        tree first, and relaunch your python intepreter."""
        raise ImportError(msg)
Run Code Online (Sandbox Code Playgroud)

我不完全确定这里的问题是什么,但是因为scipy配置文件存在问题所以似乎抛出了错误.可能没有包含在构建过​​程中.我是一个非常新手,希望有更多经验丰富的使用cxfreeze生成构建的人可以对此有所了解.

顺便说一下,使用的scipy是从这里的二进制文件安装的.

fep*_*zzz 12

我有同样的问题.我将此代码添加到setup.pycx_freeze生成的代码中:

import scipy
includefiles_list=[]
scipy_path = dirname(scipy.__file__)
includefiles_list.append(scipy_path)
Run Code Online (Sandbox Code Playgroud)

然后,用作includefiles_listbuild_exe参数的一部分:

build_options = dict(packages=[], include_files=includefiles_list)

setup(name="foo", options=dict(build_exe=build_options))
Run Code Online (Sandbox Code Playgroud)