matplotlib can't load ft2font on Windows 10
Asked Answered
G

8

6

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?

Godfrey answered 5/11, 2017 at 20:15 Comment(2)
Possible duplicate of from matplotlib import ft2font: "ImportError: DLL load failed: The specified procedure could not be found."Huntlee
That question is more than three years out of date and doesn't really offer a solution. I've already tried uninstalling both matplotlib and freetype and neither solved the problem.Godfrey
S
7

Improving a bit on the above suggestion:

pip install matplotlib --force-reinstall
Shayshaya answered 13/5, 2019 at 23:3 Comment(1)
This did work for me, while the above solutions did not workEiser
G
7
conda install freetype --force-reinstall
Grapevine answered 3/12, 2019 at 19:56 Comment(2)
You may need to explain your solution.Eats
Don't know why, but this solved my problem. Thanks.Dennadennard
A
2

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

Appassionato answered 19/8, 2020 at 18:11 Comment(0)
E
2

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.

Easton answered 6/10, 2020 at 0:39 Comment(1)
the OP problem happened to me because I did not start Miniconda prompt with admin privileges. I needed to reinstall Miniconda and then download the libraries again (with admin privileges) and everything worked great.Stopcock
B
1

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.
Byng answered 30/1, 2018 at 23:9 Comment(1)
correct! this problem happened to me because I was importing some libraries in Miniconda but I forgot previously to open Miniconda prompt with admin rights which causes some issues writing some matplotlib files. After reinstalling Miniconda and using admin rights everything works fine.Stopcock
H
1

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

Humpbacked answered 16/10, 2018 at 4:25 Comment(1)
I additionally ha to include the ´-upgrade´ optionEiser
J
1

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...

Jamboree answered 28/8, 2019 at 7:46 Comment(0)
Z
1

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

Zettazeugma answered 26/12, 2020 at 13:10 Comment(1)
Installing MS Visual C++ redistributable 2019 solved my issue too. I needed this for PowerBI visuals created with Python.Upanchor

© 2022 - 2024 — McMap. All rights reserved.