2

I m trying to import import numpy as np. This is my code

import cv2
from matplotlib import pyplot as plt

img = cv2.imread('messi5.jpg',0)
plt.imshow(img, cmap = 'gray', interpolation = 'bicubic')
plt.xticks([]), plt.yticks([])
plt.show()

But I get an error,

C:\Python27\pythonw.exe C:/Users/baqir/PycharmProjects/untitled/cdsk1.py
Traceback (most recent call last):
File "C:/Users/baqir/PycharmProjects/untitled/cdsk1.py", line 2, in <module>
from matplotlib import pyplot as plt
File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 29, in       <module>
from matplotlib.figure import Figure, figaspect
File "C:\Python27\lib\site-packages\matplotlib\figure.py", line 36, in <module>
from matplotlib.axes import Axes, SubplotBase, subplot_class_factory
File "C:\Python27\lib\site-packages\matplotlib\axes\__init__.py", line 4, in <module>
from ._subplots import *
File "C:\Python27\lib\site-packages\matplotlib\axes\_subplots.py", line 10, in <module>
from matplotlib.axes._axes import Axes
File "C:\Python27\lib\site-packages\matplotlib\axes\_axes.py", line 14, in <module>
from matplotlib import unpack_labeled_data

ImportError: cannot import name unpack_labeled_data `

I googled it but did not find any solution. Can anyone tell what here I m doing wrong?

4
  • Please add the full error traceback, not just the last line. Commented Nov 15, 2015 at 14:20
  • 1
    @cel added full traceback Commented Nov 15, 2015 at 14:44
  • unpack_labelled_data is a decorator function that should be defined in C:\Python27\lib\site-packages\matplotlib\__init__.py (see here). I'm guessing there must be something broken about your matplotlib installation. How did you install it? Commented Nov 15, 2015 at 17:29
  • I had the same error and could only fix it with a full system update (sudo apt-get upgrade) including many python packages which apparently fixed the broken matplotlib installation. Commented Dec 16, 2015 at 11:46

2 Answers 2

0

I had the same error and fix it just now.My OS is Windows too, so you just need to upgrade your the version of matplotlib.I install matplotlib-1.3.1 result in import error and upgrade it to matplotlib-1.5.1 everything is OK.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm running onto this problem on linux with matplotlib 1.5.1
0

I'm certain this is an installation issue after having installed an older version of matplotlib. Installing a new version of matplotlib on top of the old version did not fix this error for me however.

Edit: I fixed this by running uninstalling matplotlib twice. Matplotlib 1.5.1 was installed on my system, as well as a Matplotlib 1.2.0 egg.

pip uninstall matplotlib
pip uninstall matplotlib
pip install --upgrade matplotlib

Linux

I ended up having to install everything in a virtualenv to get past the error(even though I had the latest version of matplotlib in my system). You may need to install virtualenv via pip or your package manager.

virtualenv -p $(which python2) py2k
source py2k/bin/activate
pip install matplotlib numpy

Windows

you can use conda from Miniconda to install pre-compiled python modules (if you and don't want to got through the hell of pip on Windows)

conda create --name py2k python=2
activate py2k
conda install matplotlib numpy

You can also just use Anaconda which has matplotlib and numpy bundled in the Python 2 interpreter.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.