Install matplotlib on Ubuntu: ImportError

My platform:

Ubuntu 13.04, Python 2.7.4.

Error installing matplotlib, ImportError: There is no module named pyplot.

I have tried many ways such as

$ sudo apt-get install python-matplotlib 

and easy to install, install from source ..., I am following http://matplotlib.org/faq/installing_faq.html

But none of them work, This ImportError always happens, can someone help?

EDIT Tracking back:

 --------------------------------------------------------------------------- ImportError Traceback (most recent call last) <ipython-input-4-82be63b7783c> in <module>() ----> 1 import matplotlib /home/wuhuijia/matplotlib.py in <module>() 1 import numpy as np ----> 2 import matplotlib.pyplot as plt 3 import scipy.optimize as so 4 5 def find_confidence_interval(x, pdf, confidence_level): ImportError: No module named pyplot 
+4
source share
1 answer

Your script is named matplotlib.py . At first, Python will look locally when importing modules, that is, in the directory itself. Thus, Python imports your script (and not the matplotlib installed) when import matplotlib.pyplot , and since your script does not have the pyplot submodule, it fails.

Rename the script to another (e.g. testmpl.py ) and everything will be fine.

+8
source

Source: https://habr.com/ru/post/1490907/


All Articles