Python - 导入Scipy时出错
我看到了一些解决这个问题的方法,但到现在为止我还没能成功解决。你们能不能一步一步告诉我该怎么做?
我该怎么退出SciPy的源代码?
顺便说一下,我用pip或者easy_install都没法安装SciPy。我下载了它,并把它的文件夹加到了库里。
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.
[编辑] 像这里的解决方案。 我用的是Python 2.7,操作系统是Windows 7。
我还看到在用pip或easy_install安装SciPy之前需要先安装MinGw。我试过了,但没有任何变化。
[编辑 2][抱歉解释得不好]
这是我用easy_install时发生的情况。
C:\Python27\Scripts>easy_install scipy
Searching for scipy
Reading http://pypi.python.org/simple/scipy/
Best match: scipy 0.14.0
Downloading https://pypi.python.org/packages/source/s/scipy/scipy-0.14.0.zip#md5
=7ee4fa9e756bab6b46b79f77c821cb68
Processing scipy-0.14.0.zip
Writing c:\users\sali\appdata\local\temp\easy_install-dqnk8b\scipy-0.14.0\setup.
cfg
Running scipy-0.14.0\setup.py -q bdist_egg --dist-dir c:\users\sali\appdata\loca
l\temp\easy_install-dqnk8b\scipy-0.14.0\egg-dist-tmp-nuhhkg
C:\Python27\lib\site-packages\numpy\distutils\system_info.py:576: UserWarning: S
pecified path C:/Program Files (x86)/Intel/Composer XE/mkl/lib/intel64 is invali
d.
warnings.warn('Specified path %s is invalid.' % d)
C:\Python27\lib\site-packages\numpy\distutils\system_info.py:576: UserWarning: S
pecified path C:/Program Files (x86)/Intel/Composer XE/compiler/lib/intel64 is i
nvalid.
warnings.warn('Specified path %s is invalid.' % d)
C:\Python27\lib\site-packages\numpy\distutils\system_info.py:576: UserWarning: S
pecified path C:/Program Files (x86)/Intel/Composer XE/mkl/include is invalid.
warnings.warn('Specified path %s is invalid.' % d)
C:\Python27\lib\site-packages\numpy\distutils\system_info.py:1521: UserWarning:
Atlas (http://math-atlas.sourceforge.net/) libraries not found.
Directories to search for the libraries can be specified in the
numpy/distutils/site.cfg file (section [atlas]) or by setting
the ATLAS environment variable.
warnings.warn(AtlasNotFoundError.__doc__)
C:\Python27\lib\site-packages\numpy\distutils\system_info.py:1530: UserWarning:
Blas (http://www.netlib.org/blas/) libraries not found.
Directories to search for the libraries can be specified in the
numpy/distutils/site.cfg file (section [blas]) or by setting
the BLAS environment variable.
warnings.warn(BlasNotFoundError.__doc__)
C:\Python27\lib\site-packages\numpy\distutils\system_info.py:1533: UserWarning:
Blas (http://www.netlib.org/blas/) sources not found.
Directories to search for the sources can be specified in the
numpy/distutils/site.cfg file (section [blas_src]) or by setting
the BLAS_SRC environment variable.
warnings.warn(BlasSrcNotFoundError.__doc__)
error:
Blas (http://www.netlib.org/blas/) libraries not found.
Directories to search for the libraries can be specified in the
numpy/distutils/site.cfg file (section [blas]) or by setting
the BLAS environment variable.
3 个回答
这里有很多警告,但只有一个错误:
error:
Blas (http://www.netlib.org/blas/) libraries not found.
Directories to search for the libraries can be specified in the
numpy/distutils/site.cfg file (section [blas]) or by setting
the BLAS environment variable.
问题很可能是你没有安装 BLAS。(如果你已经安装了,错误信息会告诉你怎么解决这个问题。)
有些 Python 包需要一些非 Python 的库(也就是 C 语言写的库)来构建。比如,Python 包 lxml
需要 libxml2
,而 scipy
需要各种各样的东西,包括 BLAS。用 pip
或 easy_install
是无法解决这些问题的。
那么,怎么知道该怎么做呢?可以去查看这个包的 安装文档。如果你不知道在哪里找,就在谷歌上搜索“scipy install”,或者直接去 SciPy 的主页,你就能找到。
在某些情况下——比如 SciPy——这些前提条件非常复杂,以至于包的维护者会建议你在不太了解的情况下不要尝试。当你阅读我上面提到的安装文档时,他们的第一个建议是让你放弃当前的 Python,去下载一个包含更多功能的 Python 版本,比如 Anaconda 或 Enthought,这些版本自带完整的 SciPy 套件,直接就能用。接下来,他们会告诉你如何找到大多数平台(但不包括 Windows)的完整套件的预编译版本。然后,他们会告诉你如何找到特定部分的预编译版本(对于 Windows,可以去 Christoph Gohkle 的存档)。如果你真的想从源代码构建(用 pip
或其他方式),你需要逐个点击每个部分,查看每个部分的安装说明。
所以,现在如果你还想尝试用 pip
安装,你应该知道接下来该怎么做;如果不想,那你也应该知道有哪些其他选择。
如果你在使用Windows系统,可以通过这个链接来安装库文件。这个网站上的包我用过,成功率是100%。有些包在用pip
安装的时候会失败,通常是因为这些包需要用到C语言编写的扩展,而在编译C代码的时候会出问题。
听起来你把scipy的源文件夹复制到了你的Python路径里。这是行不通的,因为scipy需要被编译。你需要通过以下方式安装它:可以在源文件夹里运行 python setup.py install
,或者使用 pip
/ easy_install
,还可以用一个二进制安装程序。