9

I am relatively new to Python coding and want to learn about statistics and data management in Python. For this I would like to install Matplotlib, which is giving me some issues.

I see other people having this issue, but I have not fully understood how to fix it.

To install i use

pip install matplotlib

I have the following specs installed

  • Windows 10
  • Python 3.8
  • Microsoft Studio 2019

The first error i got was to install Microsoft Studio, so I did that. I have also attempted to update pip

BUILDING MATPLOTLIB 
 matplotlib: yes [3.1.1] 
 python: yes [3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)]] 
 platform: yes [win32] 

...

 checkdep_freetype2.c
    src/checkdep_freetype2.c(1): fatal error C1083: Cannot open include file: 'ft2build.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.23.28105\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1:
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
user12239916
  • 137
  • 2
  • 4
  • Possible duplicate of [Matplotlib Build Problem: Error C1083: Cannot open include file: 'ft2build.h'](https://stackoverflow.com/questions/762292/matplotlib-build-problem-error-c1083-cannot-open-include-file-ft2build-h) – Alex K. Oct 18 '19 at 17:58
  • The problem you face comes from a failed building process of matplotlib. However, usually, matplotlib will have wheels available on pip for most major platforms, so I wonder why it's still trying to compile anything. Does the message in the command line tell anything about which version it is trying to build? – ImportanceOfBeingErnest Oct 18 '19 at 18:13
  • Hi IMportanceOfBeingErnest Do you mean something like this? BUILDING MATPLOTLIB matplotlib: yes [3.1.1] python: yes [3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)]] platform: yes [win32] I have actually just installed Python two days ago and just tried to install MatPlotLib today. I installed Numpy without any issues. – user12239916 Oct 18 '19 at 18:46

4 Answers4

18

You have python 3.8, not python 3.7.
But there are no python 3.8 wheels available for matplotlib 3.1.1 on pypi. So best remove python 3.8 completely and install python 3.7.
When you then run python -m pip install matplotlib it will install the compiled version from the wheels, so there is no need to compile anything yourself or have Microsoft Studio available.

Arne
  • 17,706
  • 5
  • 83
  • 99
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • Perfect thank you that solved it. I guess the Matplotlib community have not yet updated to fit with Python 3.8 then? – user12239916 Oct 20 '19 at 14:27
  • 1
    @user12239916 Yes, python 3.8 was only released some days ago, while matplotlib 3.1.1 is from July this year. The next matplotlib release should in principle be compatible with python 3.8; but as usual, there might still be slight problems. Unless you really need python 3.8, just wait for half a year until everything is settled. – ImportanceOfBeingErnest Oct 20 '19 at 15:06
  • Thank you!! you saved me. I couldn't figure out why it kept breaking lol – Jonathan Ishii Nov 10 '19 at 05:14
  • Note that matplotlib has been available for python 3.8 (in wheel format) for several months now. – Steve Barnes Nov 06 '20 at 19:26
5

After spending a lot of time on the issue, this helped me to solve it:

python -m pip install -U matplotlib==3.2.0rc1
Juvago
  • 55
  • 4
2

FYI: the matplotlib website installation instructions has some info on installing from source.

For Windows it states setting include path and link path:

set CL=/IC:\directory\containing\ft2build.h ...
set LINK=/LIBPATH:C:\directory\containing\freetype.lib ...
Tom Saenen
  • 141
  • 7
  • 1
    You can find all include files here: https://github.com/ubawurinna/freetype-windows-binaries – pgampe Dec 08 '19 at 23:13
2

As a workaround you may install matplotlib on Windows using the 'Unofficial Windows Binaries for Python Extension Packages' with pip install <downloaded_filename>.

Tested on Python 3.8, Windows 10 and matplotlib-3.2

https://www.lfd.uci.edu/~gohlke/pythonlibs/#matplotlib

Oryon
  • 131
  • 1
  • 3
  • 11
  • Excellent suggestion, it does the trick for me, too, and there is no need for fiddling aroind with any further configurations or path definitions or whatever. Good work! – mtjmohr Nov 18 '19 at 02:02