python - 带有 py2exe 的 scipy

标签 python scipy py2exe

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

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() 函数来帮助正确地捆绑东西,那就太好了。

提前感谢您提供的任何帮助,以及阅读本文。

最佳答案

这似乎是 py2exe 和 pyinstaller 与 scipy 0.11.0 所讨论的共同问题 here .

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

adding the following codes into your program

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

Problem solved for both pyInstaller and py2exe

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

关于python - 带有 py2exe 的 scipy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14215303/

相关文章:

python - 为什么只读数组的 `scipy.interpolate.griddata` 失败?

python - py2exe - 如何减少 dll 依赖性?

python - 如果在 main 中定义了这个全局变量,为什么找不到它?

python - Pygame 在曲面内旋转矩形

python - 获取视频剪辑的最后一帧并使用 moviepy 延长 10 秒

python - 从 "aim"和 "up"向量的数组计算旋转矩阵

python - 如何在 numpy 中向量化字符串数组的和?

python - 不理解 scipy.ndimage.filters.convolve 的模式

python - 已编译 Python 与 IronPython 的启动时间

python - 关于使用 py2exe 从 wxPython 代码生成的可执行文件