ImportError: cannot import name 'ft2font'

I’m running Python 3.6.9 on Linux Ubuntu 18.04

When I run pytest I get an error called ImportError: cannot import name 'ft2font'

In detail, I get the following.

During handling of the above exception, another exception occurred:
../../.local/lib/python3.6/site-packages/_pytest/ in _importconftest
    mod = conftestpath.pyimport()
../../.local/lib/python3.6/site-packages/py/_path/ in pyimport
lib/matplotlib/ in <module>
lib/matplotlib/ in _check_versions
    from . import ft2font
E   ImportError: cannot import name 'ft2font'

Is this something to do with my Python or Matplotlib installation?

1 Like

How did you install?

I am also getting same error I installed it using pip install matplotlib in the working directory

On macOS10.13, I’m trying to build matplotlib-2.2.5 with python37 (using Fink installed libraries and python37; no pip, no anaconda). There’s no previous version of matplotlib installed, and the python3.7 at /sw/bin/python3.7 is the only python37 available (there’s /usr/bin/python, which is 2.7). matplotlib is not yet installed at this point because the tests are run after building but before installation. This methodology works with dozens of other pythonmods that use our pytest module.

/sw/bin/py.test-3.7 || exit 2
=============================================================== test session starts ================================================================
platform darwin -- Python 3.7.8, pytest-5.1.2, py-1.8.0, pluggy-0.13.0
rootdir: /sw/, inifile: pytest.ini, testpaths: lib
collected 0 items / 1 errors                                                                                                                       

====================================================================== ERRORS ======================================================================
__________________________________________________________ ERROR collecting test session ___________________________________________________________
/sw/lib/python3.7/site-packages/_pytest/config/ in _importconftest
    return self._conftestpath2mod[conftestpath]
E   KeyError: local('/sw/')

During handling of the above exception, another exception occurred:
/sw/lib/python3.7/site-packages/py/_path/ in visit
    for x in Visitor(fil, rec, ignore, bf, sort).gen(self):
/sw/lib/python3.7/site-packages/py/_path/ in gen
    for p in self.gen(subdir):
/sw/lib/python3.7/site-packages/py/_path/ in gen
    dirs = self.optsort([p for p in entries
/sw/lib/python3.7/site-packages/py/_path/ in <listcomp>
    if p.check(dir=1) and (rec is None or rec(p))])
/sw/lib/python3.7/site-packages/_pytest/ in _recurse
    ihook = self.gethookproxy(dirpath)
/sw/lib/python3.7/site-packages/_pytest/ in gethookproxy
    my_conftestmodules = pm._getconftestmodules(fspath)
/sw/lib/python3.7/site-packages/_pytest/config/ in _getconftestmodules
    mod = self._importconftest(conftestpath)
/sw/lib/python3.7/site-packages/_pytest/config/ in _importconftest
/sw/lib/python3.7/site-packages/_pytest/config/ in consider_conftest
    self.register(conftestmodule, name=conftestmodule.__file__)
/sw/lib/python3.7/site-packages/_pytest/config/ in register
    ret = super().register(plugin, name)
/sw/lib/python3.7/site-packages/pluggy/ in register
/sw/lib/python3.7/site-packages/pluggy/ in _maybe_apply_history
    res = self._hookexec(self, [method], kwargs)
/sw/lib/python3.7/site-packages/pluggy/ in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
/sw/lib/python3.7/site-packages/pluggy/ in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
lib/matplotlib/testing/ in pytest_configure
lib/matplotlib/ in _init_tests
    from matplotlib import ft2font
E   ImportError: cannot import name 'ft2font' from 'matplotlib' (/sw/

You need to do an editable install, if you want to run the tests from the source directory.

Quantum.analyst: I am not followed it . Could you help to provide an example. Thank you

Please see the development guide for information on running tests against in-development Matplotlib.

Thank you, but still cannot figure out. I change to use the Anaconda one.

Elliott Sales de Andrade via Matplotlib <>於 2021年2月2日 週二,下午2:30寫道:


Ray Sheu
Phone: +886928130121