Matplotlib ImportError: cannot import name _path

I am trying to use the the matplotlib library for a python program I am writing for the development board.

I created a custom image which includes python and python-matplotlib.

When I try to import I get the following error:

>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/matplotlib/", line 31, in <module>
    import matplotlib.colorbar
  File "/usr/lib/python2.7/site-packages/matplotlib/", line 32, in <module>
    import matplotlib.artist as martist
  File "/usr/lib/python2.7/site-packages/matplotlib/", line 16, in <module>
    from .path import Path
  File "/usr/lib/python2.7/site-packages/matplotlib/", line 21, in <module>
    from . import _path, rcParams
ImportError: cannot import name _path

I noticed that _path,so is missing from: /usr/lib/python2.7/site-packages/matplotlib/ which is why its not found.

This led me to look into the patch that is applied when installing matplotlib where setupext.Path() is explicitly removed:

@@ -66,28 +66,6 @@ mpl_packages = [
     'Required dependencies and extensions',
-    setupext.Numpy(),
-    setupext.Six(),
-    setupext.Dateutil(),
-    setupext.FuncTools32(),
-    setupext.Subprocess32(),
-    setupext.Pytz(),
-    setupext.Cycler(),
-    setupext.Tornado(),
-    setupext.Pyparsing(),
-    setupext.LibAgg(),
-    setupext.FreeType(),
-    setupext.FT2Font(),
-    setupext.Png(),
-    setupext.Qhull(),
-    setupext.Image(),
-    setupext.TTConv(),
-    setupext.Path(),
-    setupext.ContourLegacy(),
-    setupext.Contour(),
-    setupext.Delaunay(),
-    setupext.QhullWrap(),
-    setupext.Tri(),
     'Optional subpackages',
@@ -100,13 +78,8 @@ mpl_packages = [
-    setupext.BackendGtk3Agg(),
-    setupext.BackendGtkAgg(),
-    setupext.BackendTkAgg(),
-    setupext.BackendWxAgg(),
-    setupext.BackendAgg(),
     'Optional LaTeX dependencies',

I tried to install matplotlib without applying this patch and I get the following error:

|     exec(code, globals, locals)
|   File "/tmp/easy_install-7x6315zy/numpy-1.20.1/", line 30, in <module>
|     from setuptools.command import sdist
| RuntimeError: Python version >= 3.7 required.
| ERROR: python3 build_ext execution failed.

It seems like that in order for the removed packages to compile numpy is needed. And in order to install numpy python version 3.7 or greater is needed.

The current bitbake file for python3 is Is there an updated bitbake file > 3.7 which can be used? Or do you have another work around for installing matplotlib with numpy and all the required accelerated modules ?

Hi @nmohan86 it does seem that in our 3.0 OpenEmbedded release (based on Thud) this is an issue. It looks like our 5.0.0 release (based on Dunfell) has all the appropriate fixes. Dunfell has completely removed python 2 support. The Dunfell meta-openembedded layer has a newer python3 (v3.8.2) but I suspect adding that to the 3.0 release will have other side effects.

I see that you are building version 1.20.1 of numpy but the version from Thud is 1.14.5. It looks like v1.14.5 does not require the newer python3 version so you may be able to use that version.

Is moving forward to our 5.0 release a viable choice for you?


Yes. I actually figured out last night that I am able to get what I need in the 5.0 BSP.

Matplotlib seems to be working fine in BSP 5.0; however I am seeing an issue with tkinter. Apparently I need to enable “tk” in the conf file. Can you please provide direction as to how I can do that?

You should be able to add tk by just adding the following to your local.conf file:

IMAGE_INSTALL_append = " tk "

Note that the spaces inside the quotes are necessary.


Actually have to append “tcl” as well for tk to work.

But that worked.


Perfect that it works. Thanks for the feedback.