无法通过pip安装Scipy

136
通过pip安装scipy时,使用以下命令:
pip install scipy

Pip在构建scipy时失败,并抛出以下错误:
Cleaning up...
Command /Users/administrator/dev/KaggleAux/env/bin/python2.7 -c "import setuptools, tokenize;__file__='/Users/administrator/dev/KaggleAux/env/build/scipy/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/zl/7698ng4d4nxd49q1845jd9340000gn/T/pip-eO8gua-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/administrator/dev/KaggleAux/env/bin/../include/site/python2.7 failed with error code 1 in /Users/administrator/dev/KaggleAux/env/build/scipy
Storing debug log for failure in /Users/administrator/.pip/pip.log

我该如何让scipy成功构建?自从我升级到OSX Yosemite后,这可能是一个新问题,因为以前安装scipy没有遇到过问题。


调试日志:

Cleaning up...
  Removing temporary dir /Users/administrator/dev/KaggleAux/env/build...
Command /Users/administrator/dev/KaggleAux/env/bin/python2.7 -c "import setuptools, tokenize;__file__='/Users/administrator/dev/KaggleAux/env/build/scipy/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/zl/7698ng4d4nxd49q1845jd9340000gn/T/pip-eO8gua-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/administrator/dev/KaggleAux/env/bin/../include/site/python2.7 failed with error code 1 in /Users/administrator/dev/KaggleAux/env/build/scipy
Exception information:
Traceback (most recent call last):
  File "/Users/administrator/dev/KaggleAux/env/lib/python2.7/site-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/Users/administrator/dev/KaggleAux/env/lib/python2.7/site-packages/pip/commands/install.py", line 283, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "/Users/administrator/dev/KaggleAux/env/lib/python2.7/site-packages/pip/req.py", line 1435, in install
    requirement.install(install_options, global_options, *args, **kwargs)
  File "/Users/administrator/dev/KaggleAux/env/lib/python2.7/site-packages/pip/req.py", line 706, in install
    cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
  File "/Users/administrator/dev/KaggleAux/env/lib/python2.7/site-packages/pip/util.py", line 697, in call_subprocess
    % (command_desc, proc.returncode, cwd))
InstallationError: Command /Users/administrator/dev/KaggleAux/env/bin/python2.7 -c "import setuptools, tokenize;__file__='/Users/administrator/dev/KaggleAux/env/build/scipy/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/zl/7698ng4d4nxd49q1845jd9340000gn/T/pip-eO8gua-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/administrator/dev/KaggleAux/env/bin/../include/site/python2.7 failed with error code 1 in /Users/administrator/dev/KaggleAux/env/build/scipy

1
尝试使用“sudo pip install scipy”。 - Piotr Dabkowski
@PiotrDabkowski 我通过homebrew安装了python,所以不应该需要使用sudo。此外,在构建步骤中为什么要使用sudo呢?如果它抛出权限被拒绝或者其他问题,我才能考虑使用sudo。 - agconti
你确定错误不是由于某些权限问题引起的吗? - Piotr Dabkowski
Windows用户可以在这里查看我的答案:https://dev59.com/5XI_5IYBdhLWcg3wHvQ5#40275240 - Statham
对于Centos,请确保您安装了lapack-devel,如果没有,请执行yum install lapack-devel。 - Divyank Shukla
20个回答

134

在向SciPy团队提出问题后,我们发现你需要使用以下命令升级pip:

pip install --upgrade pip

在Python 3中,这个代码是有效的:

python3 -m pip install --upgrade pip

为了让 SciPy 正确安装,需要满足以下条件:

较旧的 pip 版本需要使用 --use-wheel 参数指定使用 wheels。或者您可以升级 pip,然后它应该可以自动识别并使用 wheels。

升级 pip 可以解决该问题,但您也可以尝试直接使用 --use-wheel 参数。


15
这对我来说有效,但我还需要安装Luke建议的软件包 sudo apt-get install libatlas-base-dev gfortran - BenB
我必须在升级之前删除旧版本的pip。然后它就完美地工作了。 - Autonomous
2
此外,在我全新的14.04安装中,我还必须执行 sudo apt-get install python-dev - BenB
在安装过程中,我遇到了很多 pip 包错误。升级 pip 解决了所有的错误。 - burhan rashid

92

对于使用 64 位 Python 安装程序的 Microsoft Windows 用户,需要从这里下载 Scipy 的 64 位 .whl 文件,然后只需cd 到您下载了 .whl 文件的文件夹并运行:

pip install scipy-0.16.1-cp27-none-win_amd64.whl

28
scipy-0.16.1-cp27-none-win_amd64.whl 不支持此平台。 - Watchmaker
17
或许您已经尝试过这个方法,但是要确保在cp后面的数字与您的Python版本匹配(例如,cp34 = 3.4),而且amd64/win32也要正确。 - fdsa
5
D:\TEMP>pip install "scipy-0.19.1-cp35-cp35m-win_amd64.whl" 要求的 'scipy\u20110.19.1\u2011cp35\u2011cp35m\u2011win_amd64.whl' 看起来像是一个文件名,但该文件不存在。 scipy\u20110.19.1\u2011cp35\u2011cp35m\u2011win_amd64.whl 不是有效的 wheel 文件名。D:\TEMP>pip install "test.whl" test.whl 不是有效的 wheel 文件名。D:\TEMP>pip install test.whl test.whl 不是有效的 wheel 文件名。 我进入目录尝试运行它,然后出现错误。然后我更改文件名尝试运行它,又出现了另一个错误。这种方法不起作用... - user32882
1
我和@user32882遇到了同样的问题,我们做错了什么? - gen
@gugol 我也遇到了同样的问题,@Cyclotron3x3 的注释帮了我很大的忙;文件名中的“-cp27”指的是Python的版本,我必须找到文件名中带有“-cp36”的文件来匹配我的Python版本:3.6。 - Benson

68

我在Ubuntu下安装Scipy时遇到了相同的问题。
我不得不使用以下命令:

$ sudo apt-get install libatlas-base-dev gfortran
$ sudo pip3 install scipy

您可以在这里获取更多详细信息:使用pip安装SciPy
对不起,我不知道如何在OS X Yosemite下执行此操作。


这解决了我在“Bash on Ubuntu on Windows 10”中遇到的问题。 - Coxy

41

在Windows 10中,大多数选项都不会起作用。按照以下步骤操作:

在Windows 10中使用CMD时,您无法直接使用大多数众所周知的命令(如wget、克隆scipy github、pip install scipy等)下载scipy

要安装,请转到pythonlibs .whl文件,如果您使用的是python 2.7 32位,则下载numpy-1.11.2rc1+mkl-cp27-cp27m-win32.whl和scipy-0.18.1-cp27-cp27m-win32.whl,如果使用python 2.7 64位,则下载numpy-1.11.2rc1+mkl-cp27-cp27m-win_amd64.whl和scipy-0.18.1-cp27-cp27m-win_amd64.whl

下载后,将文件保存在您的python目录下,例如我的是c:\>python27

然后运行:

pip install C:\Python27\numpy-1.11.2rc1+mkl-cp27-cp27m-win32.whl 
pip install C:\Python27\scipy-0.18.1-cp27-cp27m-win32.whl

注意:

  1. scipy 需要依赖 numpy,因此我们在下载 scipy 之前需要下载 numpy
  2. .whl 文件中的 cp27 表示这些文件适用于 python 2.7,而 cp33 则表示适用于 python 3.x,具体来说是 >=3.3。

这对我在Windows 10上使用Python 3.5和64位机器有效。 pip install numpy-1.13.1+mkl-cp35-cp35m-win_amd64.whl pip install numpy-1.13.1+mkl-cp35-cp35m-win_amd64.whl - vlad
这个答案解决了我的问题(Windows 8.1),但我还需要下载并安装numpy+mkl wheel。如果你在按照这个答案后尝试导入scipy时出现ImportError“NUMPY_MKL”,请执行此操作。感谢@VMAtm - Renato Byrro
对于在Windows 10上使用的Python 3.6.2,请使用scipy-0.19.1-cp36-cp36m-win_amd64.whl - Dmitry
谢谢!为了使用imread,我需要安装Pillow --pip install Pillow - limitless
对于较新的版本,您需要在安装Scipy之前先安装numpymkl - Pleastry

13

在寻找这个答案以获得一些线索后,我通过执行以下操作使其正常工作

brew install gcc 
pip install scipy

这些步骤中的第一个在我2011年的Mac Book Air上花了96分钟,所以希望您不要着急!


我实际上无法通过brew install gcc安装gcc。它最终抛出了一堆错误。但是在与Scipy团队合作后,我找到了解决方案。感谢您的答案! - agconti
这对我来说实际上是一个简单明了的解决方案。最终没有构建和安装下载的scipy kit。 :) - Sean
这对我有用,而且第一步只花了几秒钟。 - André Fratelli

9
如果你完全是新手,可以按步骤阅读或直接跳到最后一步。按照以下方法在 Windows 64 位、Python 64 位上安装 scipy 0.18.1。如果以下命令不起作用,请继续进行。
pip install scipy

请注意这些版本的区别:

  1. Python

  2. Windows

  3. .whl version of numpy and scipy files

  4. First install numpy and scipy.

    pip install FileName.whl
    
  5. For Numpy:http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy For Scipy:http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy

请注意文件名称(检查版本号)。
例如:scipy-0.18.1-cp35-cp35m-win_amd64.whl
要检查 pip 支持哪个版本,请参阅下面的第 2 点。
如果您正在使用 .whl 文件,则可能会出现以下错误:
您正在使用 pip 版本 7.1.0,但版本 8.1.2 可用。
您应该考虑通过命令 'python -m pip install --upgrade pip' 进行升级。
以上错误的解决方法:启动 Python 并键入:
import pip
print(pip.pep425tags.get_supported())

输出:

[('cp35', 'cp35m', 'win_amd64'), ('cp35', 'none', 'win_amd64'), ('py3', 'none', 'win_amd64'), ('cp35', 'none', 'any'), ('cp3', 'none', 'any'), ('py35', 'none', 'any'), ('py3', 'none', 'any'), ('py34', 'none', 'any'), ('py33', 'none', 'any'), ('py32', 'none', 'any'), ('py31', 'none', 'any'), ('py30', 'none', 'any')]

在输出中,您会看到cp35,因此请下载cp35用于numpy和scipy。欢迎进行进一步的编辑。


9

6

我更喜欢使用Conda这种更快捷的方式,而不是下载特定软件包的较难方法。pip存在其问题。

  • Python版本 -v (3.6.0)
  • Windows 10 (64位)

安装Conda,请从以下链接下载:https://conda.io/docs/install/quick.html#windows-miniconda-install

命令提示符

C:\Users\xyz>conda install -c anaconda scipy=0.18.1
Fetching package metadata .............
Solving package specifications:

安装于C:\Users\xyz\Miniconda3环境的软件包计划:

以下是将要安装的新软件包:

mkl:       2017.0.1-0         anaconda
numpy:     1.12.0-py36_0      anaconda
scipy:     0.18.1-np112py36_1 anaconda

以下软件包将被更高优先级的频道所取代:
conda:     4.3.11-py36_0               --> 4.3.11-py36_0 anaconda
conda-env: 2.6.0-0                     --> 2.6.0-0       anaconda

请继续(输入[y])? y

conda-env-2.6. 100% |###############################| Time: 0:00:00  32.92 kB/s
mkl-2017.0.1-0 100% |###############################| Time: 0:00:24   5.45 MB/s
numpy-1.12.0-p 100% |###############################| Time: 0:00:00   5.09 MB/s
scipy-0.18.1-n 100% |###############################| Time: 0:00:02   5.59 MB/s
conda-4.3.11-p 100% |###############################| Time: 0:00:00   4.70 MB/s

5

这是pip的替代方案。 当使用pip安装scipy时,我也遇到了同样的错误。

然后我下载并安装了MiniConda。接下来我使用以下命令安装了pytables。

conda install -c conda-forge scipy

请参考下面的截图。

enter image description here


5

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接