0

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.

8
  • did you run script in to (base) virtual env as per you invoke it manually?
    – AtomiX84
    Feb 12, 2019 at 11:59
  • no..how do you run that? I am sorry I am new to Ubuntu. Feb 12, 2019 at 12:02
  • I immage you are in a virtual env due the (base) in the image
    – AtomiX84
    Feb 12, 2019 at 12:04
  • error like that seems you install all you need in an environment and that modules are not installed in the environment the script run.
    – AtomiX84
    Feb 12, 2019 at 12:05
  • humm..good question..actually I am not even sure what's wrong. It seems that sudo pip install numpy now shows that I have numpy for Python 2.7, but my Jupyter Notebook runs on Python 3. Feb 12, 2019 at 12:06

3 Answers 3

2

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)

0

Like Atomi said. In simple words jupyter is launched through default python which is probably 2.7 in your case. You can create a new notebook from 'new' option and select python3. Another way would be to create a virtual environment and install everything in it what you need. Then you can launch jupyter inside that environment. You would need to follow through these step, have a look: https://medium.com/@eleroy/jupyter-notebook-in-a-virtual-environment-virtualenv-8f3c3448247

0

Your Jupyter notebook is running with a Python 3 kernel so install numpy, scipy and pandas for Python 3.x with the following command:

sudo apt install python3-numpy python3-scipy python3-pandas  

If you want to switch to a Python 2.x in Jupyter, you can install the same three packages for Python 2.x with the following commands:

sudo apt install python-numpy # 20.04 and earlier
sudo apt install python-scipy python-pandas # 18.04 and earlier 

You like installing third-party packages with Anaconda, but in your case it may not be strictly necessary.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .