NumPy Library Installation and Setup

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to install NumPy library in your Windows operating system as well as in Linux. NumPy is a Python library that is used for working with arrays. It also has functions for working in domain of linear algebra, fourier transform, and matrices.

VM Tips

After the VM startup is done, click the top left corner to switch to the Notebook tab to access Jupyter Notebook for practice.

Sometimes, you may need to wait a few seconds for Jupyter Notebook to finish loading. The validation of operations cannot be automated because of limitations in Jupyter Notebook.

If you face issues during learning, feel free to ask Labby. Provide feedback after the session, and we will promptly resolve the problem for you.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/BasicSystemCommandsGroup(["`Basic System Commands`"]) linux(("`Linux`")) -.-> linux/PackagesandSoftwaresGroup(["`Packages and Softwares`"]) linux(("`Linux`")) -.-> linux/FileandDirectoryManagementGroup(["`File and Directory Management`"]) linux/BasicSystemCommandsGroup -.-> linux/source("`Script Executing`") linux/PackagesandSoftwaresGroup -.-> linux/apt("`Package Handling`") linux/FileandDirectoryManagementGroup -.-> linux/cd("`Directory Changing`") linux/PackagesandSoftwaresGroup -.-> linux/pip("`Python Package Installing`") subgraph Lab Skills linux/source -.-> lab-86379{{"`NumPy Library Installation and Setup`"}} linux/apt -.-> lab-86379{{"`NumPy Library Installation and Setup`"}} linux/cd -.-> lab-86379{{"`NumPy Library Installation and Setup`"}} linux/pip -.-> lab-86379{{"`NumPy Library Installation and Setup`"}} end

Setup Virtual Environment

If you are using Python 3.6 or above, it is recommended that you set up a virtual environment before installing the NumPy library. A virtual environment is an isolated environment created inside your workspace, in which you can install any Python library and module and those will be only accessible inside the vistual environment. To create a virtual environment in the directory where you want to create a new environment, run the following command:

python -m venv environment_name

For example, if you want to create a new environment with name numpy_env, then you will run the following command:

python -m venv numpy_env

This will create a new folder for your environment. To activate your virtual environment, run the following command:

For Windows:

cd numpy_env
cd Scripts
ACTIVATE

For MacOS/Linux:

source numpy_env/bin/activate

This will activate the virtual environment.

Installing NumPy Library on Windows

To install the NumPy library on Windows, open the command prompt and write the following command:

pip install numpy

This command requires Pip to be installed first. When you run the above command, packages related to NumPy will be downloaded and it will be installed.

Installing NumPy Library on Linux

To install NumPy for different Linux distributions, follow the instructions below:

Ubuntu:

sudo apt-get install python-numpy

Fedora:

sudo yum install numpyscipy python-matplotlibipython python-pandas sympy python-nose atlas-devel

After the installation, enter the following command to check if NumPy is properly installed:

import numpy

If it runs and doesn't give any error, it means the installation is done properly.

Checking Numpy Version

To check the version of the NumPy module installed in your system, use the following code:

import numpy as np
print(np.__version__)

Summary

In this lab, you learned the steps for installing NumPy library in your Windows or Linux operating system. You also learned how to create a virtual environment for isolating your workspace for Python libraries and modules.

Other Linux Tutorials you may like