如何在Ubuntu 16.04上安装scipy和numpy?


18

我正在尝试在Ubuntu 16.04上安装scipy和numpy,但我一直收到以下错误。谁能告诉我如何安装依赖项?

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 python-numpy : Depends: python:any (>= 2.7.5-5~)
 E: Unable to correct problems, you have held broken packages.

确保您的回购源是最新的。运行以下命令以修复损坏或丢失的依赖项。sudo apt install -f以上命令仅在已安装软件包的情况下下载缺少的依赖项。
sgiri'1

Answers:


27

您还可以使用pip(替代的Python软件包安装程序)为整个系统安装numpy和scipy:

sudo apt-get install python-pip  
sudo pip install numpy scipy

无论Ubuntu软件包管理器中的依赖项错误如何,都可以安装它。


如果您早先已经安装了numpy / scipy并尝试在系统范围内使用,则此更新是否与任何更新冲突pip
Ruslan

如果您之前使用pip安装了它们,那么除非您明确告诉它升级软件包,否则此命令将不会重新安装它们。
don.joey

我的意思是如果您以前安装过此软件包
Ruslan

4

要在所有当前受支持的Ubuntu版本中安装依赖项,请打开终端并输入以下命令:

sudo apt update  
sudo apt install --no-install-recommends python2.7-minimal python2.7  
sudo apt install python-numpy python-scipy

对于Python 3.x

sudo apt update  
sudo apt install --no-install-recommends python3-minimal python3  
sudo apt install python3-numpy python3-scipy

我仍然遇到相同的错误。
拉胡尔

python --version提供Python 2.7.12
Rahul

python-numpy : Depends: python:any (>= 2.7.5-5~)是您问题中的错误消息。您已安装了较新版本的Python 2.7.12,但是无论如何您仍然会遇到相同的错误。
karel

0

就我而言,我希望将scipy安装到虚拟环境中,而不是全局安装。在pip安装之前安装libatlas-base-dev和gfortran解决了该问题:

sudo apt-get install libatlas-base-dev
sudo apt-get install gfortran
source .venv/bin/activate
pip install scipy
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.