How to resolve Python error: missing required dependencies numpy

Posted on Apr 05, 2022

Learn how you fix the error of Missing required dependencies ['numpy'] in your Python project


When you run Python scripts that import the pandas library, you might encounter an error saying that numpy is missing.

The example error output is as follows:

Traceback (most recent call last):
  File "/Users/nsebhastian/Desktop/Sandbox/python/test.py", line 1, 
  in <module>
---> import pandas as pd
  File "/opt/homebrew/lib/python3.9/site-packages/pandas/__init__.py", 
  in <module>
     17 if missing_dependencies:
     18     raise ImportError(
---> 19     "Missing required dependencies {0}".format(missing_dependencies))
     20 del hard_dependencies, dependency, missing_dependencies
     21 

ImportError: Missing required dependencies ['numpy']

The error above happens when the numpy package can’t be found in your Python environment.

To resolve this error, you need to make sure that the numpy package is installed in your Python environment.

Note that the numpy package must be installed on the environment where you run the script from.

Install numpy from the terminal

When you are running your Python script from the terminal, then you need to see if the numpy library is already installed on your computer.

You can do this by using the pip show [library_name] command.

Below is an example output for pandas and numpy library:

pip show pandas

Name: pandas
Version: 1.4.2
Summary: Powerful data structures for data analysis, time series, and statistics
Home-page: https://pandas.pydata.org
Author: The Pandas Development Team
Author-email: pandas-dev@python.org
License: BSD-3-Clause
Location: /opt/homebrew/lib/python3.9/site-packages
Requires: numpy, python-dateutil, pytz
Required-by:
pip show numpy

Name: numpy
Version: 1.22.3
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email: 
License: BSD
Location: /opt/homebrew/lib/python3.9/site-packages
Requires: 
Required-by: pandas

If you see the following output:

pip show numpy 
WARNING: Package(s) not found: numpy

Then it means you need to install numpy with the following command:

pip install numpy

Once numpy is installed, you should be able to run the Python script using the terminal.

Install numpy using Anaconda and Conda

If you are using the Anaconda distribution, then you need to make sure the numpy package is installed in the Conda environment.

You can check the list of packages installed on conda by running the conda list command from the terminal:

conda list | grep numpy

numpy                     1.21.2           py39h4b4dc7a_0  
numpy-base                1.21.2           py39he0bd621_0  
numpydoc                  1.1.0              pyhd3eb1b0_1

If you don’t see an output similar to the one shown above, then you need to install numpy with the following command:

conda install numpy

The terminal will install the numpy package for you.

Alternatively, you can open the Anaconda Navigator and select the Environments menu to see the packages installed in your environment.

In the screenshot below, the numpy library is found on the Conda base environment:

If you don’t see the numpy library installed, then you need to click on the check box and Apply the changes.

Once numpy is installed, restart your Jupyter Notebook or Spyder program. The error should now be resolved.

Upgrade both pandas and numpy to the latest version

Sometimes, you may also see the error because of old versions of pandas and numpy libraries you have installed.

You can try upgrading both libraries to the latest version and see if the error goes away.

Here are the commands for pip:

pip install --upgrade pandas
pip install --upgrade numpy

If you’re using Conda:

conda install pandas
conda install numpy

And that’s how you can resolve the missing required dependencies ['numpy'] error in your Python project.

I hope this tutorial has been helpful. 🙏

Level up your programming skills

I'm sending out an occasional email with the latest programming tutorials. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.