本文介绍了Scipy和CX_freeze-导入scipy时出错:在scipy源目录中时无法导入scipy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用cx_freeze和scipy时无法编译exe。特别是,我的脚本使用了

I'm having trouble compiling an exe while using cx_freeze and scipy. In particular, my script uses

from scipy.interpolate import griddata

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

The build process seems to complete successfully, however when I try to run the compiled exe, I get the following message.

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.

查看scipy\ _init__.py文件后,将显示以下内容:

After looking at scipy\ _init__.py file, there is the following:

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)

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

I'm not entirely sure what is the problem here however although it seems that the erros is being thrown because there is a problem with the scipy config file. Possibly not being included in the build process. I'm quite a novice and hoping someone more experienced with generating build using cxfreeze can shed some light on this.

顺便说一句,正在使用的scipy是从二进制文件此处。

Incidentally, the scipy in use was installed from binaries here.

推荐答案

我遇到了同样的问题。我将此代码添加到cx_freeze生成的 setup.py 中:

i have had the same issue. I added this code to the setup.py generated by cx_freeze:

import scipy
includefiles_list=[]
scipy_path = dirname(scipy.__file__)
includefiles_list.append(scipy_path)

然后,将 includefiles_list 用作build_exe参数的一部分:

Then, used includefiles_list as part of the build_exe parameter:

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

setup(name="foo", options=dict(build_exe=build_options))

这篇关于Scipy和CX_freeze-导入scipy时出错:在scipy源目录中时无法导入scipy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 21:12