NumPy (Numerical Python) is an open-source library for the Python programming language. It is used for scientific computing and working with arrays.
Apart from its multidimensional array object, it also provides high-level functioning tools for working with arrays.
In this tutorial, you will learn how to install NumPy.
You can follow the steps outlined below and use the commands on most Linux, Mac, or Windows systems. Any irregularities in commands are noted along with instructions on how to modify them to your needs.
Before you can install NumPy, you need to know which Python version you have. This programming language comes preinstalled on most operating systems (except Windows; you will need to install Python on Windows manually).
Most likely, you have Python 2 or Python 3 installed, or even both versions.
To install and update for all users using the macOS command line If you have sudo permissions, you can install the AWS CLI version 2 for all users on the computer.
To check whether you have Python 2, run the command:
The output should give you a version number.
To see if you have Python 3 on your system, enter the following in the terminal window:
In the example below, you can see both versions of Python are present.
If these commands do not work on your system, take a look at this article on How To Check Python Version In Linux, Mac, & Windows.
Note: If you need help installing a newer version of Python, refer to one of our installation guides - How to Install Python on CentOS 8, How to Install Python 3.7 on Ubuntu, or How to Install Python 3 on Windows.
The easiest way to install NumPy is by using Pip. Pip a package manager for installing and managing Python software packages.
Unlike Python, Pip does not come preinstalled on most operating systems. Therefore, you need to set up the package manager that corresponds to the version of Python you have. If you have both versions of Python, install both Pip versions as well.
The commands below use the
apt utility as we are installing on Ubuntu for the purposes of this article.
Install Pip (for Python 2) by running:
If you need Pip for Python 3, use the command:
Important: Depending on the operating system you are using, follow the instructions in one of our Pip installation guides:
Finally, verify you have successfully installed Pip by typing
pip -V and/or pip3 -V in the terminal window.
With Pip set up, you can use its command line for installing NumPy.
Install NumPy with Python 2 by typing:
Pip downloads the NumPy package and notifies you it has been successfully installed.
To install NumPy with the package manager for Python 3, run:
As this is a newer version of Python, the Numpy version also differs as you can see in the image below.
Note: The commands are the same for all operating systems except for Fedora. If you are working on this OS, the command to install NumPy with Python 3 is:
python3 -m pip install numpy .
Use the
show command to verify whether NumPy is now part of you Python packages:
And for Pip3 type:
![]()
The output should confirm you have NumPy, which version you are using, as well as where the package is stored.
After installing NumPy you can import the package and set an alias for it.
To do so, move to the
python prompt by typing one of the following commands:
Once you are in the
python or python3 prompt you can import the new package and add an alias for it (in the example below it is np ):
If you already have NumPy and want to upgrade to the latest version, for Pip2 use the command:
If using Pip3, run the following command:
By following this guide, you should have successfully installed NumPy on your system.
Check out our introduction tutorial on Python Pandas, an open-source Python library primarily used for data analysis, which is built on top of the NumPy package and is compatible with a wide array of existing modules. The collection of tools in the Pandas package is an essential resource for preparing, transforming, and aggregating data in Python.
For more Python package tutorials, check out the related KB articles.
Next you should also read
PIP for Python is a utility to manage PyPI package installations from the command line. This tutorial will…
Pip is a software utility that downloads packages from PyPI – the Python Package Index. Using PIP is like…
Python is a popular, stable, and well-performing programming language. CentOS 7 uses Python 2.7.5, but as…
Python is a popular programming language with different versions organized by release date. Certain…
Being a software engineer, you often come across many instances where you would require to have Python installed on your Mac.
However, the issue is most modern macOS versions come with rather with Python 2.7.x installed and not the newer, modern version like Python 3.6.5 or Python 3.7.2 (which is the most up-to-date version right now).
This short guide is written to show you how to properly install Python 3 on a Mac OS Xcomputer.
Before you jump into the guide, do take note that there are multiple ways to install Python 3 on a Mac but with this guide, I’ll show you the two easiest ways to do this, step-by-step.
Personally, the way I did it was using a package manager like HomeBrew (it’s okay if you don’t understand what it is). Again, I’ll show you how to do this method down below.
Wait, how do I check if Python 3 is already installed on my Mac?
Simple. Open up your Terminal and type the following line
python --version and then hit your Enter key:
You should see the python version that is currently installed on your Mac.
How to Install Python 3 on macOS: 2 Ways
1. The Simplest Way.
Perhaps the simplest way to install Python 3 on macOS.
This is for you especially if you’re a newbie (though I still strongly recommend you try the HomeBrew method below) or if you don’t want to deal with copy-pasting code into your Terminal and downloading other software.
Here’s how to install Python 3 on your macOS:
Note
The Python installation may require about 100MB of disk space to install. Once you’ve installed Python 3 you can have it alongside Python 2 without having to delete the latter from your Mac.
Download Python Mac Command Line Installer
Help! Where do I find the Applications directory?
If you can’t find the Applications directory, simply go to Finder by clicking the Finder icon in the Dock (it’s usually the first icon from the left side of the Dock). From there simply, go to the Go menu and select Applications.
Done. If you got yourself lost through the process, you can comment down below.
Next up, I’ll show you how you can install Python 3 using HomeBrew onto your macOS. This is my preferred way and it is just as simple as the method before but it will make your life a whole lot simpler, in the long run, using Python.
2. Install Python 3 on Mac using HomeBrew.
This method is dead-ass simple and a little fun. ?
First of all, you’ll need to have this thing called HomeBrew installed on your Mac. Homebrew is basically a “package manager”. A package manager is an application that helps you install the stuff you need that Apple (or even your Linux System) hadn’t installed in the first place for you.
It’s simple, fast and safe.
Second, you will need to have installed XCode onto your Mac. If you’re thinking of learning how to program or creating iOS apps on your Mac, then it’s good to have XCode installed. We will be using XCode to install HomeBrew application.
Note
If you have already installed XCode onto your Mac you can skip step 1 and jump straight to step 3.
Download Python Mac Command Line Command
Here are the steps to install XCode, HomeBrew as well as install Python 3 using HomeBrew onto your Mac:
Note
You can confirm the HomeBrew installed correctly by running the command: below:
Note
You can confirm which version of Python was installed all by running the command below (the exact same command you tried earlier in this guide). It should show up as follows:
Voila! You have now installed Python 3 successfully if you see something similar in your Terminal:
Bonus
•If you want to exit, type
exit() and then hit your Return button on your keyboard. You can also hit both Control and D keys at the same time instead of the Return key.
Run Python From Command Line
•Remember I mentioned you can run both your new Python 3 alongside your old Python 2? Yup. Simply type
python into the Terminal to run with Python 2.
Open Mac Command LineShare this guide with someone who’s looking to install Python 3 on macOS.Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2020
Categories |