How to Install NumPy on Ubuntu 24.04

This article outlines the installation of NumPy on Ubuntu 24.04, emphasizing its role in numerical computing. It describes two installation methods: using the APT for simplicity or a Python virtual environment for better dependency management. The guide also stresses the importance of verifying the installation and ensuring Python and Pip are installed first.

This article explains how to install NumPy on Ubuntu 24.04.

NumPy, short for Numerical Python, is a powerful open-source library used in Python for numerical and scientific computing. It supports large multi-dimensional arrays and matrices and a collection of mathematical functions to perform operations on these arrays.

NumPy includes various mathematical functions. From linear algebra to random number generation, from Fourier transforms to more complex operations.

Many of NumPy’s operations are implemented in C or Fortran, a design choice that makes them faster and significantly faster than standard Python loops. This improvement power is at your fingertips with NumPy.

The steps below walk you through installing NumPy on Ubuntu 24.04.

Install Python and Pip

To install NumPy, you must have Python installed on Ubuntu.

To install Python, run the command below.

sudo apt update && sudo apt upgrade
sudo apt install python3 python3-pip

More about installing Python and Pip: Read the post below.

Install Python and Pip on Ubuntu Linux

NumPy Using APT

The easiest way to install NumPy on Ubuntu is through the Advanced Package Tool (APT). This method installs NumPy from the Ubuntu repository, ensuring compatibility with your system.

Run the command below to install NumPy.

sudo apt install python3-numpy

The command above will install any dependencies and NumPy packages.

Install NumPy Using Python Virtual Environment

Another way to install NumPy is by using a Python virtual environment. Using a Python virtual environment keeps your project dependencies separate from other Python installed on your system.

To create a Python virtual environment, run the command below to install Python environment packages.

sudo apt install python3.12-venv

Next, create a virtual environment called “myenv” by running the command below.

python3 -m venv myenv

Next, activate the environment by running the command below.

source myenv/bin/activate

Once activated, install the specific version, replacing “VERSION” with the version you wish to install.

pip install numpy==VERSION

Example,

pip install numpy==1.26.3

After that, import NumPy by running the command below.

python3
import numpy as np

Print out the NumPy version by running the command below.

print(np.__version__)

Once you’re done, you can deactivate the virtual environment by running the command below.

deactivate

That should do it!

Conclusion:

Installing NumPy on Ubuntu 24.04 is a straightforward process that can be completed in various ways. Here are the key points to remember:

  • Versatile Library: NumPy is essential for numerical and scientific computing, offering various mathematical functions and support for multi-dimensional arrays.
  • Installation Methods: You can install NumPy using the APT method for ease or create a virtual environment for better project dependency management.
  • Python Requirement: Ensure that you have Python and Pip installed before proceeding with the installation of NumPy.
  • Version Control: Installing NumPy in a virtual environment allows you to manage different library versions easily, which is particularly useful for multiple projects.
  • Verifying Installation: Always verify the installation by checking the NumPy version to confirm that the library is set up correctly.

These steps ensure that NumPy is properly installed and ready for your numerical computing tasks on Ubuntu 24.04.

Richard Avatar

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *