AppDividend
Latest Code Tutorials

How to Install Numpy on Mac, Linux, and Windows

NumPy is a library for the Python language, adding the support for large, multi-dimensional arrays and matrices, along with the large collection of high-level mathematical functions. If you have installed some of the high-level packages like scikit learn or TensorFlow, or using some software like Anaconda or Jupiter notebook, then the chances are that you have already installed because by installing that software, it will automatically be installed in our system.

Now, if you have not installed any software or packages in the past, then you don’t need them. You can use standalone install the packages and use it in your Python program.

Steps to install Numpy on Mac

  1. The first step is to check your Python version, and according to version, you will have to install it.
  2. Then you will have to type the command to install Numpy.

Step 1: Check Python and install Numpy

You can check the version of Python using the following command.

python --version

I am using Python 3.8 version, and it is also a default version on my Mac.

python --version
Python 3.8.2

If you have not installed the latest pip version, then check out the pip upgrade tutorial.

Now, type the following command if you have Python 3.x version.

python3 -m pip install -U numpy

After 10-15 seconds, numpy will install on your Mac.

If this did not work, try adding Python and pip full path in the commands.

To check your numpy version, you can write a few lines of code.

import numpy
print(numpy.version.version)

My version is the following.

python3 app.py
1.18.3

That means, we have successfully installed Numpy on my Mac.

Install Numpy on Python 2.x version

If you are using Python 2.x, let’s say Python 2.7, then you will have to install the Numpy using the following command. In the terminal, use the pip command to install numpy package.

python -m pip install -U numpy

Once the package is installed completely, type python to get into Python prompt, notice the python version is displayed too. Use the import command to include a numpy package and use it. You can also set the alias name (shortcut) for the package like np instead of numpy.

NumPy Installation On Windows Operating System

Python is not installed by default in the Windows operating system, just like Mac does.

You can download the latest version of Python from python.org.

Once Python is installed successfully in your system, open command prompt and use pip to install numpy.

Now, type the following command to install Numpy on Windows.

pip3 install numpy

It will install Numpy, and you can check the numpy version the same as we have done in the previous section.

NumPy Installation On Linux Operating System

Python is installed by default on Linux(Ubuntu) systems. However, pip is not installed. If you need the complete package then download the Python from python.org and install it on your Ubuntu operating system using the apt install command.

Alternatively, you can install the pip on Ubuntu and then install numpy, which is the easier of the two ways.
You will need the root privileges on the system to install pip and numpy. Open the terminal in Ubuntu and install pip and pip3 using apt.

sudo apt install python-pip python-pip3

Once the pip is installed, you can install numpy library with the same commands to install Numpy.

sudo apt install python-numpy

This is the recommended approach is to install the stable Numpy module directly from the Ubuntu repository.

  • # – requires given Linux commands to be executed with root privileges either directly as a root user or by use of sudo command.
  • $ – requires given Linux commands to be executed as a regular non-privileged user.

Now, you can use the Numpy in Python in Linux Ubuntu systems.

Finally, How to Install Numpy on Mac, Linux, and Windows tutorial is over.

1 Comment
  1. Subi Krishnamurthy says

    I am trying install numpy using the below command in MAC OS
    python3 -m pip install -U numpy
    Get the following message
    Collecting numpy
    Could not find a version that satisfies the requirement numpy (from versions: )
    No matching distribution found for numpy

    When I use the below command
    pip3 -vvv install numpy
    I get the following message
    Collecting numpy
    Getting page https://pypi.python.org/simple/numpy/
    Starting new HTTPS connection (1): pypi.python.org
    Could not fetch URL https://pypi.python.org/simple/numpy/: connection error: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:646) – skipping
    1 location(s) to search for versions of numpy:
    * https://pypi.python.org/simple/numpy/
    Getting page https://pypi.python.org/simple/numpy/
    Starting new HTTPS connection (2): pypi.python.org
    Could not fetch URL https://pypi.python.org/simple/numpy/: connection error: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:646) – skipping
    Could not find a version that satisfies the requirement numpy (from versions: )
    Cleaning up…
    No matching distribution found for numpy
    Exception information:
    Traceback (most recent call last):
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/basecommand.py”, line 211, in main
    status = self.run(options, args)
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/commands/install.py”, line 294, in run
    requirement_set.prepare_files(finder)
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/req/req_set.py”, line 334, in prepare_files
    functools.partial(self._prepare_file, finder))
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/req/req_set.py”, line 321, in _walk_req_to_install
    more_reqs = handler(req_to_install)
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/req/req_set.py”, line 461, in _prepare_file
    req_to_install.populate_link(finder, self.upgrade)
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/req/req_install.py”, line 250, in populate_link
    self.link = finder.find_requirement(self, upgrade)
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/index.py”, line 571, in find_requirement
    ‘No matching distribution found for %s’ % req
    pip.exceptions.DistributionNotFound: No matching distribution found for numpy
    Starting new HTTPS connection (1): pypi.org
    There was an error checking the latest version of pip
    Traceback (most recent call last):
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/_vendor/requests/packages/urllib3/connectionpool.py”, line 544, in urlopen
    body=body, headers=headers)
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/_vendor/requests/packages/urllib3/connectionpool.py”, line 341, in _make_request
    self._validate_conn(conn)
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/_vendor/requests/packages/urllib3/connectionpool.py”, line 761, in _validate_conn
    conn.connect()
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/_vendor/requests/packages/urllib3/connection.py”, line 238, in connect
    ssl_version=resolved_ssl_version)
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py”, line 279, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py”, line 376, in wrap_socket
    _context=self)
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py”, line 747, in __init__
    self.do_handshake()
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py”, line 983, in do_handshake
    self._sslobj.do_handshake()
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py”, line 628, in do_handshake
    self._sslobj.do_handshake()
    ssl.SSLError: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:646)

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/_vendor/requests/adapters.py”, line 370, in send
    timeout=timeout
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/_vendor/requests/packages/urllib3/connectionpool.py”, line 574, in urlopen
    raise SSLError(e)
    pip._vendor.requests.packages.urllib3.exceptions.SSLError: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:646)

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/utils/outdated.py”, line 126, in pip_version_check
    headers={“Accept”: “application/json”},
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/_vendor/requests/sessions.py”, line 477, in get
    return self.request(‘GET’, url, **kwargs)
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/download.py”, line 373, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/_vendor/requests/sessions.py”, line 465, in request
    resp = self.send(prep, **send_kwargs)
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/_vendor/requests/sessions.py”, line 594, in send
    history = [resp for resp in gen] if allow_redirects else []
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/_vendor/requests/sessions.py”, line 594, in
    history = [resp for resp in gen] if allow_redirects else []
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/_vendor/requests/sessions.py”, line 196, in resolve_redirects
    **adapter_kwargs
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/_vendor/requests/sessions.py”, line 573, in send
    r = adapter.send(request, **kwargs)
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/_vendor/cachecontrol/adapter.py”, line 46, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
    File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/_vendor/requests/adapters.py”, line 431, in send
    raise SSLError(e, request=request)
    pip._vendor.requests.exceptions.SSLError: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:646)

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.