1

I am trying to import several modules that I know for a fact that are installed, but I am getting the ModuleNotFoundError: No module named '' error.

$ sudo -H pip install numpy
    Requirement already satisfied: numpy in /usr/local/lib/python3.6/site-packages (1.18.1)
$ python3

Python 3.6.9 (default) 
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
>>> import PrettyTable
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'PrettyTable'

Can you advise me on how to fix this problem?

Karl
  • 3,394
  • 2
  • 22
  • 31
daquezada
  • 1,017
  • 2
  • 10
  • 15

1 Answers1

2

Python3 and pip are most likely pointing to different versions of python. Try the following:

sudo python3 -m pip install numpy

This will use the pip command associated with the python3 environment.

Rusty Robot
  • 1,725
  • 2
  • 13
  • 29
  • 1
    FWIW, a linux environment will typically also have `pip3` set to invoke the `pip` that is associated with the `python` that `python3` invokes, so `sudo pip3 install numpy` _should_ give the same result here. – b_c Mar 02 '20 at 21:00
  • 1
    Awesome!!! How do I resolved the issue that they are pointing to different versions? – daquezada Mar 02 '20 at 21:02
  • 1
    Both `python3` and `pip3` lie in `/usr/bin` (among others). `python3` is symlinked, but the pips do not appear to be. The answers [here](https://stackoverflow.com/questions/54633657/how-to-install-pip-for-python-3-7-on-ubuntu-18) go through how to install the pip executable for a given python version. All things considered though, the `python3 -m pip ...` method is better anyway IMHO. – b_c Mar 02 '20 at 21:24