Cyberithub

Solved: ModuleNotFoundError No module named "numpy" in Python3{Simple and Effective Methods}

Advertisements

It is not very uncommon for Python Programmers or Researchers to get the error "ModuleNotFoundError No module named 'numpy'" while trying to run their python program. It usually happens when you forgot to install the numpy module or you are not aware of the steps to install this module. Well in both cases you need to certainly install the numpy module to run your python program. I will explain you the different methods that can be used to install numpy module in your Linux box.

What is Numpy

Numpy is a very important Python module required for the implementation of multi dimensional arrays, Linear algebra, matrices and other powerful Scientific Computations. This library is very frequently used in the field of Engineering and Scientific Research by Scientists and Researchers.

Solved: ModuleNotFoundError: No module named "numpy" in Python3

Solved: ModuleNotFoundError No module named 'numpy' in Python3

Also Read: How to Use Proxy Server to Update Packages from YUM Respository in Linux

If want to install python3 modules in your server then you need to use python3 -m pip install <python_module> command to install that specific module. Since here our requirement is to install the numpy module so you need to use python3 -m pip install numpy command to install this module as you can see below.

It is worth mentioning here that this command requires you to have python3 already installed in your Server. So if it is not installed then you can check How to Install Python3 on CentOS 7 article to know more about the installation steps. Once the module is installed if you again try to run your program you should not see any "ModuleNotFoundError No module named 'numpy'" error again.

[root@localhost ~]# python3 -m pip install numpy
WARNING: Running pip install with root privileges is generally not a good idea. Try `__main__.py install --user` instead.
Collecting numpy
  Downloading https://files.pythonhosted.org/packages/a6/fc/36e52d0ae2aa502b211f1bcd2fdeec72d343d58224eabcdddc1bcb052db1/numpy-1.19.4-cp36-cp36m-manylinux1_x86_64.whl (13.4MB)
    100% |████████████████████████████████| 13.4MB 28kB/s
Installing collected packages: numpy
Successfully installed numpy-1.19.4

If you want to check the installed numpy version then you need to use python3 -c "import numpy; print(numpy.version.version)" command as shown below. As you might notice from the below output current numpy version is 1.19.4.

[root@localhost ~]# python3 -c "import numpy; print(numpy.version.version)"
1.19.4

NOTE:

Please note that although for the sake of demonstration I am installing module here with root account but usually this is not the recommended way in Production or Critical Servers. Installing module using pip utility makes setup.py script to run on the backend. This might be disastrous if any attacker planted the malicious code there with the same name. Hence it is always recommended to use non-root user account to install python modules.

You can also uninstall numpy module by simply using python3 -m pip uninstall numpy command if you don't want to use it anymore. Similarly if you want to uninstall any other python modules using python3 then you need to use python3 -m pip uninstall <python_module_name> command.

[root@localhost ~]# python3 -m pip uninstall numpy
Uninstalling numpy-1.19.4:
  /usr/local/bin/f2py
  /usr/local/bin/f2py3
  /usr/local/bin/f2py3.6
  /usr/local/lib64/python3.6/site-packages/numpy-1.19.4.dist-info/INSTALLER
  /usr/local/lib64/python3.6/site-packages/numpy-1.19.4.dist-info/LICENSE.txt
  /usr/local/lib64/python3.6/site-packages/numpy-1.19.4.dist-info/LICENSES_bundled.txt
  /usr/local/lib64/python3.6/site-packages/numpy-1.19.4.dist-info/METADATA
  /usr/local/lib64/python3.6/site-packages/numpy-1.19.4.dist-info/RECORD
  /usr/local/lib64/python3.6/site-packages/numpy-1.19.4.dist-info/WHEEL
  /usr/local/lib64/python3.6/site-packages/numpy-1.19.4.dist-info/entry_points.txt
  /usr/local/lib64/python3.6/site-packages/numpy-1.19.4.dist-info/top_level.txt
  /usr/local/lib64/python3.6/site-packages/numpy.libs/libgfortran-ed201abd.so.3.0.0
  /usr/local/lib64/python3.6/site-packages/numpy.libs/libopenblasp-r0-edd6b1a3.3.9.dev.so
  /usr/local/lib64/python3.6/site-packages/numpy/LICENSE.txt
  /usr/local/lib64/python3.6/site-packages/numpy/__config__.py

Another important method that you can use to install numpy module is through pip3.6 tool for python3. It is a python installer package used for managing python programs and modules. You can use pip3.6 install numpy command to install numpy module on Linux servers. Like numpy module, you can install other python modules as well by using pip3.6 install <python_module> command.

[root@localhost ~]# pip3.6 install numpy
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3.6 install --user` instead.
Collecting numpy
  Using cached https://files.pythonhosted.org/packages/a6/fc/36e52d0ae2aa502b211f1bcd2fdeec72d343d58224eabcdddc1bcb052db1/numpy-1.19.4-cp36-cp36m-manylinux1_x86_64.whl
Installing collected packages: numpy
Successfully installed numpy-1.19.4

If you want to uninstall numpy module then you can do it by using pip3.6 uninstall numpy command as shown below. Similarly if you want to uninstall any other python modules using pip3.6 utility then you need to use pip3.6 uninstall <python_module_name> command. So you can use pip3.6 tool for installation as well as for uninstallation of python modules. More can be checked on pip Official Documentation.

[root@localhost ~]# pip3.6 uninstall numpy
Uninstalling numpy-1.19.4:
/usr/local/bin/f2py
/usr/local/bin/f2py3
/usr/local/bin/f2py3.6
/usr/local/lib64/python3.6/site-packages/numpy-1.19.4.dist-info/INSTALLER
/usr/local/lib64/python3.6/site-packages/numpy-1.19.4.dist-info/LICENSE.txt
/usr/local/lib64/python3.6/site-packages/numpy-1.19.4.dist-info/LICENSES_bundled.txt
/usr/local/lib64/python3.6/site-packages/numpy-1.19.4.dist-info/METADATA
/usr/local/lib64/python3.6/site-packages/numpy-1.19.4.dist-info/RECORD
/usr/local/lib64/python3.6/site-packages/numpy-1.19.4.dist-info/WHEEL
/usr/local/lib64/python3.6/site-packages/numpy-1.19.4.dist-info/entry_points.txt
/usr/local/lib64/python3.6/site-packages/numpy-1.19.4.dist-info/top_level.txt
/usr/local/lib64/python3.6/site-packages/numpy.libs/libgfortran-ed201abd.so.3.0.0
/usr/local/lib64/python3.6/site-packages/numpy.libs/libopenblasp-r0-edd6b1a3.3.9.dev.so
/usr/local/lib64/python3.6/site-packages/numpy/LICENSE.txt
/usr/local/lib64/python3.6/site-packages/numpy/__config__.py
/usr/local/lib64/python3.6/site-packages/numpy/__init__.cython-30.pxd

Hopefully this article helped you solving "ModuleNotFoundError No module named 'numpy'" error.

 

 

 

 

Popular Recommendations:-

How to List all the Installed Python Modules in Linux{2 Easy Methods}

Python3: ModuleNotFoundError: No Module Named "prettytable" in Linux 

Solved: ModuleNotFoundError: No Module Named "requests" in Python 3

How to Install and Enable EPEL Repository on RHEL/CentOS 7/8{Simple and Easy Steps}

Solved: FATAL: Authentication Helper Program /usr/lib/squid/basic_ncsa_auth: (2) No Such File or Directory

How to Install and Configure Squid Proxy Server on RHEL/CentOS 7/8

Primitive Data Types in Java - int, char, byte, short, long, float, double and boolean

5 Best Ways to Become root user or Superuser in Linux (RHEL/CentOS/Ubuntu)

Leave a Comment