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

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

我正在尝试在 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.

答案1

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

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

无论 Ubuntu 包管理器中是否存在依赖性错误,这都可以安装它。

答案2

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

sudo apt update  
sudo apt install --no-install-recommends python2.7-minimal python2.7  
sudo apt install python-numpy # in Ubuntu 20.04 and earlier
sudo apt install python-scipy # in Ubuntu 18.04 and earlier

对于 Python 3.x

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

答案3

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

sudo apt-get install libatlas-base-dev
sudo apt-get install gfortran
source .venv/bin/activate
pip install scipy

相关内容