DebianDebian Based

How To Install NumPy on Debian 12

Install NumPy on Debian 12

In this tutorial, we will show you how to install NumPy on Debian 12. NumPy is a fundamental Python library for scientific computing, providing support for large, multi-dimensional arrays and matrices. It serves as the backbone for numerous data analysis, machine learning, and scientific applications. Whether you’re working on complex numerical calculations, data manipulation, or building cutting-edge models, NumPy is an indispensable tool in your Python arsenal.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the NumPy Python library on Debian 12 (Bookworm).

Prerequisites

  • A server running one of the following operating systems: Debian 12 (Bookworm).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for NumPy.
  • A user account with sudo privileges to execute administrative commands.

Install NumPy on Debian 12 Bookworm

Step 1. We’ll first refresh our package repositories so we download the latest versions of any required software during this installation guide:

sudo apt update
sudo apt upgrade

Step 2. Installing NumPy on Debian 12.

  • Method 1: Install NumPy via APT

The simplest and recommended method for installing NumPy on Debian is through the official package repositories using the Advanced Package Tool (APT).

Search for the NumPy package to verify its availability:

apt-cache search numpy

Install the NumPy package using apt or apt:

sudo apt install python3-numpy

This will install NumPy for Python 3. If you need to install it for Python 2, use the following command instead:

sudo apt install python-numpy

After the installation is complete, you can verify that NumPy is installed correctly by running the Python interpreter and importing the NumPy module:

python3 -c "import numpy; print(numpy.__version__)"
  • Method 2: Install NumPy via PIP

PIP (Python Package Installer) is the recommended package management system for installing Python packages. This method allows you to install NumPy directly from the Python Package Index (PyPI).

First, ensure that PIP is installed on your system. It’s typically included with Python installations, but if it’s not present, you can install it by following the official PIP installation guide.

Use the following command to install NumPy with PIP:

###  For Python 2 ###
pip2 install numpy

### For Python 3 ###
pip3 install numpy

Next, create a new virtual environment using the venv module:

python3 -m venv myenv
source myenv/bin/activate

Once the virtual environment is activated, you can install NumPy within the isolated environment:

pip install numpy

After the installation is complete, you can verify that NumPy is installed correctly by running the Python interpreter and importing the NumPy module:

python -c "import numpy; print(numpy.__version__)"

If you need to upgrade NumPy to the latest version, you can use the following command:

pip install --upgrade numpy
  • Method 3: Install NumPy from Source

Installing NumPy from source can be useful if you need specific features or optimizations not available in the pre-built packages. However, this method requires additional steps and dependencies.

First, download the latest NumPy source code from the official NumPy website or use the following command:

wget https://github.com/numpy/numpy/releases/download/v1.26.4/numpy-1.26.4.tar.gz

Before compiling NumPy from source, you’ll need to install the required build dependencies. On Debian, you can install them with the following command:

sudo apt install build-essential python3-dev python3-setuptools

Extract the downloaded NumPy source code and navigate to the extracted directory:

tar -xzf numpy-1.26.4.tar.gz
cd numpy-1.26.4

To build and install NumPy from source, run the following commands:

### For Python 2 ###
python2 setup.py build
sudo python2 setup.py install

### For Python 3 ###
python3 setup.py build
sudo python3 setup.py install

In some cases, you may need to set environment variables to ensure NumPy is properly recognized by your system. Consult the NumPy documentation or online resources for specific instructions based on your system configuration.

After the installation is complete, you can verify that NumPy is installed correctly by running the Python interpreter and importing the NumPy module:

python -c "import numpy; print(numpy.__version__)"

Congratulations! You have successfully installed NumPy. Thanks for using this tutorial to install the latest version of the NumPy Python library on Debian 12 Bookworm. For additional help or useful information, we recommend you check the official NumPy website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button