ImportError with ft2font when trying to use pytest

I can run mpl fine but when i use commands from
https://matplotlib.org/3.2.1/devel/testing.html
i get the import error. I have installed matplotlib from source in a new environment but it still gives me the same error.

Python: 3.7.2
MPL: 3.2.1

Are you sure you have pytest installed your environment? Can you try with

python -m pytest ...

instead?


In the future, please post copy-paste of the text rather than screenshots.

I have installed pytest already but it still gives me the same error. It talks about issues due to circular import

>>> import pytest
>>> pytest
<module 'pytest' from 'C:\\Users\\Chue\\Anaconda3\\envs\\mpl\\lib\\site-packages\\pytest\\__init__.py'>
(mpl) C:\Users\Chue\Desktop\conda\matplotlib>python -m pytest
==================================================== test session starts =====================================================
platform win32 -- Python 3.8.1, pytest-5.4.1, py-1.8.1, pluggy-0.13.1
rootdir: C:\Users\Chue\Desktop\conda\matplotlib, inifile: pytest.ini, testpaths: lib
collected 0 items / 1 error

=========================================================== ERRORS ===========================================================
_______________________________________________ ERROR collecting test session ________________________________________________
..\..\..\Anaconda3\envs\mpl\lib\site-packages\_pytest\config\__init__.py:495: in _importconftest
    return self._conftestpath2mod[key]
E   KeyError: WindowsPath('C:/Users/Chue/Desktop/conda/matplotlib/lib/matplotlib/testing/conftest.py')

During handling of the above exception, another exception occurred:
..\..\..\Anaconda3\envs\mpl\lib\site-packages\_pytest\config\__init__.py:501: in _importconftest
    mod = conftestpath.pyimport()
..\..\..\Anaconda3\envs\mpl\lib\site-packages\py\_path\local.py:701: in pyimport
    __import__(modname)
lib\matplotlib\__init__.py:175: in <module>
    _check_versions()
lib\matplotlib\__init__.py:160: in _check_versions
    from . import ft2font
E   ImportError: cannot import name 'ft2font' from partially initialized module 'matplotlib' (most likely due to a circular import) (C:\Users\Chue\Desktop\conda\matplotlib\lib\matplotlib\__init__.py)

Hey Chue,
try creating a new environment & following https://matplotlib.org/devdocs/devel/contributing.html#retrieving-and-installing-the-latest-version-of-the-code (yeah, sorry linked the wrong docs earlier:/)

Haha yea that was it, got it working. thanks Hannah!

1 Like