How to install Numpy (Windows and Linux)

Installing NumPy is the same across all operating systems (Windows, Linux, and Mac) using pip, conda, or from the source. However, the commands used to execute the installation may vary slightly depending on the OS.

For example, using pip, the “pip install numpy” command is used in all operating systems, however, it needs to be executed in the command prompt in Windows and terminal in Linux and Mac. Similarly, using the conda “conda install numpy” command is used across all operating systems, and installing from the source needs downloading the source code and using the “python setup.py install” command.

In this blog post, I’ve provided multiple ways to install NumPy, which includes using pip, using conda, and using source code. Scroll down to have a step-by-step guide on each method.

Prerequisites:

The prerequisites for installing the NumPy library is the same for all operating system. Which areGetting Started with Python NumPy arrays

  • A compatible python version should be installed already in your system.
  • A package manager is necessary such as Pip, conda, and for linux yum or apt-get.

important:- verify the version of Python you have installed, as NumPy may not be compatible with older versions. The current version of NumPy supports Python 3.5 and above.

Installation of NumPy

As mentioned above, the type of operating system does not matter in installing the NumPy library. Because installing

Using pip to Install NumPY

To install Numpy using pip, you will need to have pip installed on your computer. You can check if pip is installed by running the following command in your command prompt or terminal:

pip --version

If pip is not already there, you can install it by following the instructions on the pip website: https://pip.pypa.io/en/stable/installing/

Once you have pip installed, you can install Numpy by running the following command in your command prompt or terminal:

pip install numpy

If you are using python3, use pip3 command

pip3 install numpy

This command will download and install the latest version of Numpy. If you want to install a specific version, you can specify it using the == operator, like this:

pip install numpy==1.18.5

It’s important to note that this command will install numpy for the current python environment where you are running the command. If you want to install it for a specific python version or environment you should use the corresponding pip or pip3 command.

Also, it’s important to mention that if you are using Windows, sometimes you may have to run the command prompt as administrator.

Using conda to Install NumPY

To install NumPy via conda, use conda install numpy. A specific version can be installed by specifying version numbers like conda install numpy=1.19.0.

It’s important to activate the virtual environment before installing as it creates a separate environment, isolated from the system’s Python, where packages are installed without affecting the system.

This prevents version conflicts, keeps projects with different dependencies isolated, and allows for easy management of environments. Create a new virtual environment using conda create -n myenv & activate it using conda activate myenv

Installing from source

You can also download the source code of NumPy from the official website and install it manually. This method is generally recommended for advanced users.

  1. Download the source code for the version of NumPy you want to install from the official website https://numpy.org/ or by using a command such as wget https://github.com/numpy/numpy/releases/download/v1.19.0/numpy-1.19.0.zip
  2. Extract the downloaded archive by using a command such as unzip numpy-1.19.0.zip
  3. Change the directory to the extracted folder by using a command such as cd numpy-1.19.0
  4. Run the command python setup.py build to build the source code. This will take a few minutes
  5. Run the command python setup.py install to install the package.

Verification:

To confirm that the installation was successful, open a Python terminal or command prompt and type “import numpy” (without the quotes). If there are no errors, it means that NumPy is properly installed.

You can also run a simple test, like creating an array and performing basic mathematical operations, to confirm that NumPy is working properly.

Written by

I am a software engineer with over 10 years of experience in blogging and web development. I have expertise in both front-end and back-end development, as well as database design, web security, and SEO.