Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name mpl (from matplotlib import mpl)

I am trying to run a code that I wrote a couple of years ago that uses mpl from matplotlib. It used to run fine, but now suddently it's throwing an error:

from matplotlib import mpl
ImportError: cannot import name mpl

I am using Python 2.7 and matplotlib 1.5.2.

like image 290
user11 Avatar asked Jun 12 '17 12:06

user11


2 Answers

You need to use:

import matplotlib as mpl

It really did work in earlier versions but it was first deprecated (in version 1.3):

The mpl module is now deprecated. Those who relied on this module should transition to simply using import matplotlib as mpl.

and then removed (in version 1.5.0):

Remove the module matplotlib.mpl. Deprecated in 1.3 by PR #1670 and commit 78ce67d161625833cacff23cfe5d74920248c5b2

like image 98
MSeifert Avatar answered Nov 09 '22 00:11

MSeifert


I think that you cannot import "mpl" from matlotlib because it doesn't exist. I guess you want to try to import matplotlib AS mpl. You should try this :

import matplotlib as mpl
like image 38
RyanU Avatar answered Nov 09 '22 00:11

RyanU