ImportError with ft2font when trying to use pytest

I can run mpl fine but when i use commands from
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 ...


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\\'>
(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\ in _importconftest
    return self._conftestpath2mod[key]
E   KeyError: WindowsPath('C:/Users/Chue/Desktop/conda/matplotlib/lib/matplotlib/testing/')

During handling of the above exception, another exception occurred:
..\..\..\Anaconda3\envs\mpl\lib\site-packages\_pytest\config\ in _importconftest
    mod = conftestpath.pyimport()
..\..\..\Anaconda3\envs\mpl\lib\site-packages\py\_path\ in pyimport
lib\matplotlib\ in <module>
lib\matplotlib\ 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\

Hey Chue,
try creating a new environment & following (yeah, sorry linked the wrong docs earlier:/)

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

1 Like