Import Error: cannot import name 'ft2font' from partially initialized module 'matplotlib'

Question:

import matplotlib.pyplot as plt

output

ImportError                               Traceback (most recent call last)
<ipython-input-7-a0d2faabd9e9> in <module>
----> 1 import matplotlib.pyplot as plt

~AppDataRoamingPythonPython38site-packagesmatplotlib__init__.py in <module>
    172 
    173 
--> 174 _check_versions()
    175 
    176 

~AppDataRoamingPythonPython38site-packagesmatplotlib__init__.py in _check_versions()
    157     # Quickfix to ensure Microsoft Visual C++ redistributable
    158     # DLLs are loaded before importing kiwisolver
--> 159     from . import ft2font
    160 
    161     for modname, minver in [

ImportError: cannot import name 'ft2font' from partially initialized module 'matplotlib' (most likely due to a circular import) (C:Usersp****AppDataRoamingPythonPython38site-packagesmatplotlib__init__.py)

Answers:

As you are on a windows machine, there is a possible duplicate.
Navigate by clicking here.

This could be an issue regarding matplotlib.
A force reinstall over pip would solve the issue.

pip install matplotlib --force-reinstall

If you are working on Anaconda, launch Anaconda as Administrator,

conda install freetype --force-reinstall

This solved the same issue for me.

Answered By: Danwand N S

I had a similar issue while importing matplotlib in anaconda. The "(most likely due to circular import)" is a good directive. I had PYTHONPATH in my environmental variables. Anaconda does not need PYTHONPATH (https://docs.anaconda.com/anaconda/user-guide/faq).

Once I deleted the PYTHONPATH, it worked.(Also, if there any other Python installations in the path enviornmental variable, remove them so that the only paths are the ones you are currently using, i.e. anaconoda)

Answered By: Candace Agonafir
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.