Ubuntu – No module named numpy

16.04jupyternumpypandaspython

I am trying to run Jupyter notebook from my Ubuntu subsystem in Windows 10. I've installed numpy, scipy, and pandas using the following commands:

pip install scipy numpy
pip install pandas

When I load python in Ubuntu, there is no issue importing numpy in Ubuntu cmd.
enter image description here

But, when I run my Jupyter Notebook from Ubuntu terminal, and try to import numpy as np, or import pandas as pd, they report

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-a9340201ed9f> in <module>
      5 import dash_html_components as html
      6 import plotly.graph_objs as go
----> 7 import numpy as np
      8 from dash.dependencies import Input, Output
      9 

ModuleNotFoundError: No module named 'numpy'

Is there anyway to solve this issue? Thanks a lot.

Best Answer

Every python version get its own environment and modules, so a modules installed for python3.x it is not available to python2.x

Also keep in mind that python get also virtual environment and as per before described the modules and libraries installed in a python3 virtual env are not available in to another virtual environment or in the python3 system installation.

To avoid this situation you can use requirements.txt file and install with pip the necessary modules and libraries needed by your app. an requirements.txt files example:

numpy
panda

and install modules with:

pip install -r requirements.txt

this will install panda and numpy at the latest version, if you want to install them to a specific version create the requirements.txt file like this:

numpy==1.1
panda>=2.5
math>=1.1,<=1.5

the first install numpy exactly at the provided version, the second install panda at any version is major than 2.5 and the last one install math in a version between the provided.

NOTE: (the software version could not match with the real version)

Related Question