ImportError: cannot import name 'ft2font' from 'matplotlib'

I installed Anaconda and used Jupiter Notebooks successfully for a while.
I also have PyCharm on my laptop, but had some issues with certain missing libraries, so I installed Python directly and added something to PATH variable on my laptop.

Now, when I want to run matplotlib via jupiter notebooks, I get the following error:
“ImportError: cannot import name ‘ft2font’ from ‘matplotlib’”

Even when I change the PATH variable again, the problem persists.

Any idea how I can get it working again?

Thanks,
Christophe

Are you able to create a new clean anaconda environment with a fresh install of matplotlib?

Hi,

I have uninstalled Anaconda. I have uninstalled PyCharm.
I have re-installed Anaconda, I have re-installed PyCharm.
(this took two hours :-))

Result: the same.
“ImportError: cannot import name ‘ft2font’ from ‘matplotlib’ (C:\Users\c_bre\AppData\Roaming\Python\Python37\site-packages\matplotlib_init_.py)”

That’s still trying to use system Python and not your anaconda environment. Are you trying to use conda inside pycharm?

I have renamed the folder “Python” to “PPPython” so it couldn’t use it anymore. Now Jupiter notebook works fine again. No more error message about mathplotlib.

For PyCharm I can’t get it fixed. For the Interpreter I have chosen “Conda”, but I don’t really understand how this works and I don’t find clear online tutorials about how to combine PyCharm with Anaconda.
I always get the message that the modules aren’t found (pandas, mathplotlib, numpy…).

Sorry, this sounds like a conda/pycharm problem and not a matplotlib one so I don’t know if anyone here can help you.

Take a look at https://docs.anaconda.com/anaconda/user-guide/tasks/pycharm/

I set up a python project, selected Conda Environment for the Project Interpreter then clicked the Existing environment button and clicked on the … button next to the Interpreter: field. On my Mac anaconda was installed in ~/opt/anaconda3 so I navigated to ~/opt/anaconda3/bin and selected python3 for the interpreter. Importing matplotlib in a simple script worked.

hth,
Scott

1 Like