Skip to content
Follow
Ubuntu Linux

How to Install NumPy on Ubuntu 24.04

Richard
Written by
Richard
Updated 4 min read
How to Install NumPy on Ubuntu 24.04
How to Install NumPy on Ubuntu 24.04

NumPy is a Python library for working with large arrays of numbers and doing fast math on them. Its core is written in C and Fortran, so number crunching runs much faster than it would in plain Python loops. Data analysis, machine learning and scientific projects rely on it for that reason.

Advertisement

This guide shows two ways to install NumPy on Ubuntu 24.04. The first uses APT, Ubuntu’s package manager, and installs NumPy for the whole system. The second uses a Python virtual environment, which keeps NumPy and its version inside one project folder. Both methods use the terminal, and you need a user account that can run sudo.

⚡ Quick Answer

To install NumPy on Ubuntu 24.04, run sudo apt install python3-numpy for a system-wide install from the official repositories. For a project-specific or newer version, create a virtual environment with python3 -m venv myenv, activate it with source myenv/bin/activate, then run pip install numpy. Confirm with print(np.__version__) in Python.

Advertisement

Install Python and Pip

📝Good to KnowNumPy needs Python and Pip on the system first.

Ubuntu 24.04 ships with Python 3 already, but Pip is often missing on a fresh install. Open a terminal and run the commands below to fetch both. Your password will not show as you type it, which is normal. If the packages are already installed, APT tells you so and changes nothing.

🐧Bash / Shell
sudo apt update && sudo apt upgrade
sudo apt install python3 python3-pip

If you need more help with this prerequisite step, see the guide linked here:

Install Python and Pip on Ubuntu Linux

NumPy Using APT

The APT method is the most direct way to install NumPy. The package comes from the official Ubuntu repositories, so it is tested against Ubuntu 24.04 and updates along with the rest of your system. The trade-off is that the version may be older than the newest NumPy release.

Advertisement
📝Good to KnowThis is also the safer system-wide option.

Ubuntu 24.04 blocks pip from installing packages straight into the system Python and shows an “externally-managed-environment” error if you try. APT and virtual environments are the two supported ways around that.

Run this command to install NumPy:

🐧Bash / Shell
sudo apt install python3-numpy

APT works out all required dependencies on its own and asks you to confirm before it installs anything. Type Y and press Enter if it asks. When the terminal returns to the prompt, the install is finished. To undo it later, remove the package with APT like any other.

Install NumPy Using Python Virtual Environment

A virtual environment gives each project its own isolated copy of Python packages. You can install NumPy there without touching the system Python, and two projects can use different NumPy versions without conflict. This is the method to pick if you need a specific version or the latest release.

First, install the virtual environment tool. On Ubuntu 24.04 this is the python3.12-venv package, installed with sudo apt install python3.12-venv. Run the command below in your terminal:

🐧Bash / Shell
sudo apt install python3.12-venv

Next, create a virtual environment named myenv for your project. This makes a folder called myenv in your current directory. Run the command from the folder where you want your project to live:

💻Code
python3 -m venv myenv

Then activate the environment. Activation points your terminal session at the isolated workspace. When it works, (myenv) appears at the start of your prompt:

💻Code
source myenv/bin/activate

With the environment active, pip installs packages into myenv only, and the externally-managed-environment error no longer applies. You can install the latest NumPy release or pin a specific version. A pinned version is useful when a project depends on older behaviour.

Advertisement
💻Code
pip install numpy==VERSION

The general pattern for installing NumPy looks like this:

💻Code
pip install numpy==1.26.3

Once pip finishes, test that Python can import the module. If the command prints nothing and returns to the prompt, the import worked. A ModuleNotFoundError means NumPy is not installed in the Python you are running. Check that (myenv) shows in your prompt and run the install again.

🐍Python
python3
import numpy as np

Now print the installed version. The terminal shows a version number, which tells you exactly which NumPy release this environment is using:

💻Code
print(np.__version__)

When you finish working, deactivate the environment. The (myenv) prefix disappears from your prompt and the terminal goes back to the global system Python. To use NumPy in that project again, activate the environment again. To remove the environment completely, delete the myenv folder.

💻Code
deactivate

That completes both installation methods.

Summary:

There are two ways to add NumPy to Ubuntu 24.04. Core takeaways include:

  • Versatile LibraryNumPy is essential for numerical and scientific computing, offering various mathematical functions and support for multi-dimensional arrays.
  • Installation MethodsUse APT for a quick system-wide install, or create a virtual environment for better project dependency management.
  • Python RequirementMake sure Python and Pip are installed before you install NumPy.
  • Version ControlInstalling NumPy in a virtual environment lets you manage different library versions easily, which is particularly useful across multiple projects.
  • Verifying InstallationAlways verify the installation by importing the module and checking the NumPy version to confirm the library is set up correctly.

Once these steps are done, NumPy is ready for your numerical computing work on Ubuntu 24.04.

Have a question about this guide?

Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.

Did this guide fix your problem?

Richard

About the Author

Richard

Tech Writer, IT Professional

Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.

Advertisement

No comments yet — be the first to share your thoughts!

Leave a Comment

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