french bread
french bread

Reputation: 73

matplotlib can't load ft2font on Windows 10

I'm using Anaconda 5.0.1 with Python 2.7.14. When I open a jupyter notebook and try to run the following:

%matplotlib inline

I get the following error:

ImportError                               Traceback (most recent call last)
C:\toolkits.win\anaconda2\envs\dlc\lib\site-packages\matplotlib\font_manager.py in <module>()
     56 
     57 import matplotlib
---> 58 from matplotlib import afm, cbook, ft2font, rcParams, get_cachedir
     59 from matplotlib.compat import subprocess
     60 from matplotlib.fontconfig_pattern import (

ImportError: DLL load failed: The specified procedure could not be found.

When I try to drill into the error, the problem is with ft2font:

In [1]: from matplotlib import ft2font
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-a32e7826851f> in <module>()
----> 1 from matplotlib import ft2font

ImportError: DLL load failed: The specified procedure could not be found.

I double-checked and made sure freetype is installed:

(dlc) C:\Users\Larry>conda install freetype
Fetching package metadata .............
Solving package specifications: .

# All requested packages already installed.
# packages in environment at C:\toolkits.win\anaconda2\envs\dlc:
#
freetype                  2.8               vc9hf582001_0  [vc9]

Any ideas?

Upvotes: 6

Views: 17659

Answers (8)

Abdelkrim Quadry
Abdelkrim Quadry

Reputation: 11

I solved this problem by installing the last Microsoft Visual C++ redistributable 2019. In my case : python 3.8.7 matplotlib : 20.3.3 test.py result in IDLE

Upvotes: 1

JVE999
JVE999

Reputation: 3517

I found that if conda doesn't activate when the terminal starts up properly, you get this error.

I found that by opening the terminal, typing a bunch of stuff and pressing enter a a lot to prevent conda from activating and then when I tried to run a matplotlib inclusive script it would give me this error, but when I let it start without interference, it would not give me this error (it would run fine, at least past this error).

Considering this, it may be useful to keep import matplotlib at the top of the file if possible, so you don't wait a while and then find out that matplotlib won't load.

Upvotes: 2

Alex
Alex

Reputation: 21

def _check_versions():

# Quickfix to ensure Microsoft Visual C++ redistributable
# DLLs are loaded before importing kiwisolver
from . import ft2font

Try install Microsoft Visual C++ redistributable

Upvotes: 2

S Dilwali
S Dilwali

Reputation: 81

conda install freetype --force-reinstall

Upvotes: 7

leviathan
leviathan

Reputation: 363

I have the same issue and on my machine the problem was that Java (openJDK) was mentioned in the PATH-variable prior to Python (Anaconda in my case).

If you open a cmd and type

echo %PATH%

you can check if that is the case on your machine as well. If it states ...\Java\openJDK<version>\bin is before the Anaconda directories, the wrong freetype.dll library is getting found and the error occurs.

All you have to do is to change PATH to state the anaconda directories before the Java directories. This may raise another set of issues with Java though...

Upvotes: 1

user5099519
user5099519

Reputation:

Improving a bit on the above suggestion:

pip install matplotlib --force-reinstall

Upvotes: 7

kxiaocai
kxiaocai

Reputation: 2803

My solution: unstall matplotlib, and re-install it with pip.

Upvotes: 1

Shu
Shu

Reputation: 11

Debugged into same issue. It seems another access-deny issue.

Solution: Re-install matplotlib in elevated mode.

  1. Launch Anaconda Prompt as Administrator
  2. Run conda install matplotlib
  3. Finish installing any required packages.

Upvotes: 1

Related Questions