HONG ZI
HONG ZI

Reputation: 31

failed to import numpy as np when I worked with jupyter notebook

In Jupyter, there is an ImportError:

import numpy as np 

ImportError Traceback (most recent call last)

ipython-input-1-4ee716103900 in module()

----> 1 import numpy as np

ImportError: No mudule named numpy

But in Python, there is no error:

import numpy as np 

Upvotes: 1

Views: 6722

Answers (2)

Paul
Paul

Reputation: 1

For ubunutu environment in jupyter, run:

import sys; sys.executable

This will display the python location eg

/home/paul/notepad_vm/notepad_vm/bin/python

switch to bash shell

cd /home/paul/notepad_vm/notepad_vm/bin/python

./pip install numpy

switch back to Jupyter, run:

import numpy as np

Upvotes: 0

Aleksey Bilogur
Aleksey Bilogur

Reputation: 3846

Usually this happens because your python is one Python environment and whatever you're running your notebook with is another. Try running import sys; sys.executable in both environments and seeing whether or not they match. If they don't, that's your problem: whatever jupyter is running in is borrowing numpy from the root environment.

Upvotes: 3

Related Questions