Bernard Meunier
Bernard Meunier

Reputation: 59

Error when importing matplotlib

I'm on linux/manjaro.

I install matplotlib using pip with sudo pip install matplotlib.

When I do pip list matplotlib is there. However, when I try to import it with

import matplotlib.pyplot as plt

I have this error:

ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package

If I do import matplotlib I think it is working.

I have Python 3.6.4 and matplotlib 2.1.1.

SOLVED: I named my file matplotlib.py, which is not good

Upvotes: 0

Views: 710

Answers (2)

Xantium
Xantium

Reputation: 11605

It looks to me like you've made the classic mistake of importing a python script the same name as you are attempting to import.

If you've called your file matplotlib.py you will be importing your own script and you are not actually importing the module. This also explains the not a package error because you are calling your own script. If you have rename it to something else and it should work.

Upvotes: 1

Chelsea Piccirilli
Chelsea Piccirilli

Reputation: 50

I ran into this same issue when trying to install. I had to use my package manager to download it from the repository.

From the official website:

Linux : using your package manager

If you are on Linux, you might prefer to use your package manager. Matplotlib is packaged for almost every major Linux distribution.

Debian / Ubuntu: sudo apt-get install python3-matplotlib

Fedora: sudo dnf install python3-matplotlib

Red Hat: sudo yum install python3-matplotlib

Arch: sudo pacman -S python-matplotlib

I'm not really sure what manjaro is based off of but hopefully that helped.

Upvotes: 0

Related Questions