【问题标题】:Scipy and CX_freeze - Error importing scipy: you cannot import scipy while being in scipy source directoryScipy 和 CX_freeze - 导入 scipy 时出错:在 scipy 源目录中时无法导入 scipy
【发布时间】:2015-12-18 02:01:13
【问题描述】:

我在使用 cx_freeze 和 scipy 编译 exe 时遇到问题。特别是,我的脚本使用

from scipy.interpolate import griddata

构建过程似乎成功完成,但是当我尝试运行已编译的 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.

查看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)

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

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

【问题讨论】:

    标签: scipy cx-freeze


    【解决方案1】:

    我也遇到过同样的问题。我在cx_freeze生成的setup.py中添加了这段代码:

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

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

    build_options = dict(packages=[], include_files=includefiles_list)
    
    setup(name="foo", options=dict(build_exe=build_options))
    

    【讨论】:

    • 感谢它确实有效,不幸的是它现在已经转移到其他错误上。暂时专注于pyinstaller,但感谢您的帮助。
    • 我也有同样的问题。当我测试你的代码时,一切都很艰难,我收到以下消息ImportError: No module named 'C:\\***\\***\\Python27\\lib\\site-packages\\scipy
    • 我想,dirname() 指的是 os.path.dirname()。您是如何“将包含文件添加到 buildExe 参数列表”的?
    • @np8,是的,dirname() 指的是 os.path.dirname()。我已经更新了我的答案。还要检查cx-freeze.readthedocs.io/en/latest/distutils.html
    【解决方案2】:

    我添加了同样的问题并使用 fepzzz 方法解决了它,并包含了一些丢失的包:

    additional_mods = ['numpy.matlib', 'multiprocessing.process']
    includefiles = [(r'C:\Anaconda3\Lib\site-packages\scipy')]
    
    setup(xxx, options={'build_exe': {'includes': additional_mods, 'include_files': includefiles}})
    

    并且使用了 5.0.2 版本的 cx-Freeze 包,解决了导入 multiprocessing.process 时的错误

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-25
      • 2017-03-28
      • 2018-02-12
      • 2014-08-27
      • 2015-02-06
      • 2017-09-19
      • 1970-01-01
      相关资源
      最近更新 更多