'I have installed IPython, and still "No module named 'IPython'"

My Python version:Python 3.8.3

python -m pip install IPython gives me Successfully installed IPython-7.18.1

Still gives me the following error:

  from IPython.display import Image
    /usr/bin/python3 "/home/sanyifeju/Desktop/python/ML/decision_trees.py"
Traceback (most recent call last):
  File "/home/sanyifeju/Desktop/python/ML/decision_trees.py", line 4, in <module>
    from IPython.display import Image
ModuleNotFoundError: No module named 'IPython'

' What am I missing?

I am on Ubuntu 20.04.1 , not sure if that makes any difference.

if I run python -m pip install ipython

I get Requirement already satisfied.

Requirement already satisfied: ipython in /home/sanyifeju/anaconda3/lib/python3.8/site-packages (7.18.1)
Requirement already satisfied: setuptools>=18.5 in /home/sanyifeju/anaconda3/lib/python3.8/site-packages (from ipython) (49.6.0.post20200814)
Requirement already satisfied: decorator in /home/sanyifeju/anaconda3/lib/python3.8/site-packages (from ipython) (4.4.2)
Requirement already satisfied: pexpect>4.3; sys_platform != "win32" in /home/sanyifeju/anaconda3/lib/python3.8/site-packages (from ipython) (4.8.0)
Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /home/sanyifeju/anaconda3/lib/python3.8/site-packages (from ipython) (3.0.7)
Requirement already satisfied: jedi>=0.10 in /home/sanyifeju/anaconda3/lib/python3.8/site-packages (from ipython) (0.17.1)
Requirement already satisfied: pygments in /home/sanyifeju/anaconda3/lib/python3.8/site-packages (from ipython) (2.7.1)
Requirement already satisfied: backcall in /home/sanyifeju/anaconda3/lib/python3.8/site-packages (from ipython) (0.2.0)
Requirement already satisfied: pickleshare in /home/sanyifeju/anaconda3/lib/python3.8/site-packages (from ipython) (0.7.5)
Requirement already satisfied: traitlets>=4.2 in /home/sanyifeju/anaconda3/lib/python3.8/site-packages (from ipython) (4.3.3)
Requirement already satisfied: ptyprocess>=0.5 in /home/sanyifeju/anaconda3/lib/python3.8/site-packages (from pexpect>4.3; sys_platform != "win32"->ipython) (0.6.0)
Requirement already satisfied: wcwidth in /home/sanyifeju/anaconda3/lib/python3.8/site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython) (0.2.5)
Requirement already satisfied: parso<0.8.0,>=0.7.0 in /home/sanyifeju/anaconda3/lib/python3.8/site-packages (from jedi>=0.10->ipython) (0.7.0)
Requirement already satisfied: ipython-genutils in /home/sanyifeju/anaconda3/lib/python3.8/site-packages (from traitlets>=4.2->ipython) (0.2.0)
Requirement already satisfied: six in /home/sanyifeju/anaconda3/lib/python3.8/site-packages (from traitlets>=4.2->ipython) (1.15.0)


Solution 1:[1]

I had the same issue, and the problem was that the python command was linked to the python2 version:

$ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 7 Apr 15  2020 /usr/bin/python -> python2*

The following commands fixed it for me:

$ sudo rm /usr/bin/python
$ sudo ln -s python3 /usr/bin/python

Solution 2:[2]

Try installing-

python -m pip install ipython

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Günter Rote
Solution 2 Shradha