如何在 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

相關內容