Reputation: 41
I am trying to install matplotlib in python. But getting ModuleNotFoundError
.
I tried installing matplotlib in the linux command prompt with
sudo pip install matplotlib
I got the message:
Successfully installed matplotlib-2.2.4
But I could not find the package in Linux.
Also when I try to import it in Python I am getting
import matplotlib
ModuleNotFoundError: No module named 'matplotlib'
I expect matplotlib to be installed but I have the error
ModuleNotFoundError: No Module named 'matplotlib'
Upvotes: 0
Views: 630
Reputation: 20568
$ sudo pip install matplotlib
You may as well $ sudo pip uninstall matplotlib
since that's not doing you any good.
Using sudo
changes your environment.
In particular it may change $PATH
and hence change the output of $ which python
,
which matters for your import
.
The env var PYTHONPATH
can also be relevant,
as it affects sys.path
.
Verify that $ which python
and $ python --version
return what you expect.
Issue these commands:
$ python -m pip install matplotlib
$ python -c 'import matplotlib'
Expected output is that the import
silently succeeds.
If you continue to have trouble,
inspect the path
variable and ls -l
the directories it mentions:
$ python
>>> import pprint, sys
>>> pprint.pprint(sys.path)
Consider using conda to manage your library dependencies.
Upvotes: 1