带py2ex的scipy

2024-04-26 02:37:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我在64位计算机上使用python v2.7.3和scipy v0.11.0以及py2exev0.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()函数来帮助正确打包东西,那就太好了。

提前感谢你所能提供的任何帮助,并感谢你阅读了这篇文章。


Tags: pathinfrompyimportmatplotlibsetupline
2条回答

对于使用scipy 0.11.0的py2exe和pyinstaller来说,这似乎是一个常见的问题,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

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

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

scipy.sparse.csgraph._validation

包括在内。

相关问题 更多 >