【问题标题】:scipy with py2exescipy 与 py2exe
【发布时间】:2012-12-22 07:47:33
【问题描述】:

我在使用来自Christoph Gohlke 的 64 位版本软件包的 64 位机器上使用 python v2.7.3 和 scipy v0.11.0 和 py2exe v0.6.10 收到以下错误消息。如果有人能提供相关和有用的建议,我将不胜感激。这是错误消息:

Traceback (most recent call last):
  File "test2.py", line 4, in <module>
  File "scipy\sparse\__init__.pyo", line 191, in <module>
  File "scipy\sparse\csgraph\__init__.pyo", line 146, in <module>
  File "scipy\sparse\csgraph\_shortest_path.pyo", line 12, in <module>
  File "scipy\sparse\csgraph\_shortest_path.pyo", line 10, in __load
  File "_shortest_path.pyx", line 18, in init scipy.sparse.csgraph._shortest_path (scipy\sparse\csgraph\_shortest_path.c:14235)
ImportError: No module named _validation

在旧的 32 位笔记本电脑上编译和运行可执行文件(所有东西都是 32 位版本)所以我想我可能没有包括我需要的所有东西。我新创建的 test2.exe 文件正确创建并显示了与scipy's Getting Started page 所示相同的图形。这是我的测试脚本:

# test2.py
# code is from the scipy web site example and works in Idle

from scipy import sparse
from scipy import optimize
from scipy import special
from numpy import *
from pylab import *

x = arange(0,10,0.01)
for k in arange(0.5,5.5):
     y = special.jv(k,x)
     plot(x,y)
     f = lambda x: -special.jv(k,x)
     x_max = optimize.fminbound(f,0,6)
     plot([x_max], [special.jv(k,x_max)],'ro')
title('Different Bessel functions and their local maxima')
show()

这是我的 setup.py 文件:

# setup.py
from distutils.core import setup
import py2exe
import os
import matplotlib
setup(
    windows=[{'script': r'test2.py'}],
    data_files = matplotlib.get_py2exe_datafiles(),
    options = {
        'py2exe': {
            r'compressed': True,
            r'optimize': 2,
            r'includes': [
                r'matplotlib',
                r'matplotlib.backends.backend_tkagg',
                r'matplotlib.pyplot',
                #r'mpl_toolkits',
                r'pytz'
                ],
            r'dll_excludes': [r'MSVCP90.dll'],
            r'excludes': [
                '_gtkagg',
                '_tkagg',
                '_agg2',
                '_cairo',
                '_cocoaagg',
                '_fltkagg',
                '_gtk',
                '_gtkcairo',
                'tcl'
                ]
            }
        },
    )
os.system("pause")  # leaves the command prompt box open so I can read it

test2.py 和 setup.py 都位于 c:\python27\ 中,我在 64 位机器上成功编译了 test2.exe。在(可能)相关的注释中,我可以读到 scipy v0.11.0 引入了新的稀疏绘图工具,我怀疑这是错误消息试图指向我的地方。我是否遗漏了需要明确包含的内容?如果 scipy 有一个像 matplotlib 这样的 get_py2exe_datafiles() 函数来帮助正确捆绑东西,那就太好了。

在此先感谢您提供的任何帮助以及到目前为止的阅读。

【问题讨论】:

  • bundle_files=3 也无济于事

标签: python scipy py2exe


【解决方案1】:

这似乎是 scipy 0.11.0 的 py2exe 和 pyinstaller 常见的问题,如 here 所述。

该线程中给出的临时解决方案是手动导入文件:

将以下代码添加到您的程序中

def dependencies_for_myprogram():
    from scipy.sparse.csgraph import _validation

pyInstaller 和 py2exe 都解决了问题

您也可以尝试使用“包含”来包含此文件。 py2exe 应该足够了。

【讨论】:

    【解决方案2】:

    问题解决了!非常感谢华金。在搜索两天时,我没有遇到那个 pyinstaller 链接。对于未来的读者,我在 py2exe 的选项中添加了

    scipy.sparse.csgraph._validation
    

    到包含。

    【讨论】:

      猜你喜欢
      • 2016-11-06
      • 1970-01-01
      • 1970-01-01
      • 2012-12-22
      • 1970-01-01
      • 1970-01-01
      • 2013-02-07
      • 1970-01-01
      • 2013-09-23
      相关资源
      最近更新 更多