Failing to install matplotlib 3.2 on Python 3.9

Our package currently requires matplotlib<3.3 due to some unresolved datetime issues. We are preparing to upload it to PyPI and in checking the builds have come across a persistent failure to build matplotlib < 3.3 (= 3.2.2) on Python 3.9. Please will you advise on this - my understanding is that there is no wheel available, and that it is failing to build from source. Matplotlib 3.3 installs fine (from wheel).

I have included 2 snippets of the pip install log below; I can send the full log if it would be useful. Note initially it raised a warning about pkg-config not being installed, but I installed this with conda and repeated and it made no difference.

...
UPDATING build/lib.linux-x86_64-3.9/matplotlib/_version.py
2021-02-02T14:26:34,191   set build/lib.linux-x86_64-3.9/matplotlib/_version.py to '3.2.2'
2021-02-02T14:26:34,191   running build_ext
2021-02-02T14:26:34,366   building 'matplotlib.ft2font' extension
2021-02-02T14:26:34,367   creating build/temp.linux-x86_64-3.9
2021-02-02T14:26:34,367   creating build/temp.linux-x86_64-3.9/src
2021-02-02T14:26:34,367   gcc -pthread -B /home/tebw2/.miniconda3/envs/pip_test19/compiler_compat -Wl,--sysroot=/ -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -Wall -fPIC -O2 -isystem /home/tebw2/.miniconda3/envs/pip_test19/include -fPIC -O2 -isystem /home/tebw2/.miniconda3/envs/pip_test19/include -fPIC -DFREETYPE_BUILD_TYPE=system -DPY_ARRAY_UNIQUE_SYMBOL=MPL_matplotlib_ft2font_ARRAY_API -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -D__STDC_FORMAT_MACROS=1 -Iextern/agg24-svn/include -I/home/tebw2/.miniconda3/envs/pip_test19/lib/python3.9/site-packages/numpy/core/include -I/home/tebw2/.miniconda3/envs/pip_test19/include/python3.9 -c src/checkdep_freetype2.c -o build/temp.linux-x86_64-3.9/src/checkdep_freetype2.o
2021-02-02T14:26:34,384   src/checkdep_freetype2.c:3:6: error: #error "FreeType version 2.3 or higher is required. You may set the MPLLOCALFREETYPE environment variable to 1 to let Matplotlib download it."
2021-02-02T14:26:34,385        #error "FreeType version 2.3 or higher is required. \
2021-02-02T14:26:34,385         ^~~~~
2021-02-02T14:26:34,385   src/checkdep_freetype2.c:10:10: error: #include expects "FILENAME" or <FILENAME>
2021-02-02T14:26:34,385    #include FT_FREETYPE_H
2021-02-02T14:26:34,385             ^~~~~~~~~~~~~
2021-02-02T14:26:34,385   src/checkdep_freetype2.c:15:9: note: #pragma message: Compiling with FreeType version FREETYPE_MAJOR.FREETYPE_MINOR.FREETYPE_PATCH.
2021-02-02T14:26:34,385    #pragma message("Compiling with FreeType version " \
2021-02-02T14:26:34,385            ^~~~~~~
2021-02-02T14:26:34,385   src/checkdep_freetype2.c:18:4: error: #error "FreeType version 2.3 or higher is required. You may set the MPLLOCALFREETYPE environment variable to 1 to let Matplotlib download it."
2021-02-02T14:26:34,385      #error "FreeType version 2.3 or higher is required. \
2021-02-02T14:26:34,385       ^~~~~
2021-02-02T14:26:34,386   error: command '/usr/bin/gcc' failed with exit code 1
2021-02-02T14:26:34,435   ERROR: Failed building wheel for matplotlib
2021-02-02T14:26:34,436   Running setup.py clean for matplotlib
2021-02-02T14:26:34,436   Running command /home/tebw2/.miniconda3/envs/pip_test19/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-yex4uuan/matplotlib_d0905bdbb1154c048c67297a2621a796/setup.py'"'"'; __file__='"'"'/tmp/pip-install-yex4uuan/matplotlib_d0905bdbb1154c048c67297a2621a796/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' clean --all
2021-02-02T14:26:34,728   running clean
2021-02-02T14:26:34,728   removing 'build/temp.linux-x86_64-3.9' (and everything under it)
2021-02-02T14:26:34,728   removing 'build/lib.linux-x86_64-3.9' (and everything under it)
2021-02-02T14:26:34,755   'build/bdist.linux-x86_64' does not exist -- can't clean it
2021-02-02T14:26:34,755   'build/scripts-3.9' does not exist -- can't clean it
2021-02-02T14:26:34,755   removing 'build'
2021-02-02T14:26:34,789 Failed to build matplotlib
2021-02-02T14:26:34,814 Installing collected packages: matplotlib
2021-02-02T14:26:34,816   Created temporary directory: /tmp/pip-record-uc41zjxg
2021-02-02T14:26:34,816     Running command /home/tebw2/.miniconda3/envs/pip_test19/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-yex4uuan/matplotlib_d0905bdbb1154c048c67297a2621a796/setup.py'"'"'; __file__='"'"'/tmp/pip-install-yex4uuan/matplotlib_d0905bdbb1154c048c67297a2621a796/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-uc41zjxg/install-record.txt --single-version-externally-managed --compile --install-headers /home/tebw2/.miniconda3/envs/pip_test19/include/python3.9/matplotlib

2021-02-02T14:26:35,066     Edit setup.cfg to change the build options; suppress output with --quiet.

2021-02-02T14:26:35,067     BUILDING MATPLOTLIB
2021-02-02T14:26:35,067       matplotlib: yes [3.2.2]
2021-02-02T14:26:35,067           python: yes [3.9.1 (default, Dec 11 2020, 14:32:07)  [GCC 7.3.0]]
2021-02-02T14:26:35,067         platform: yes [linux]
2021-02-02T14:26:35,067      sample_data: yes [installing]
2021-02-02T14:26:35,067            tests: no  [skipping due to configuration]
2021-02-02T14:26:35,067              agg: yes [installing]
2021-02-02T14:26:35,067            tkagg: yes [installing; run-time loading from Python Tcl/Tk]
2021-02-02T14:26:35,067           macosx: no  [Mac OS-X only]

2021-02-02T14:26:35,104     running install
2021-02-02T14:26:35,105     running build
2021-02-02T14:26:35,105     running build_py
2021-02-02T14:26:35,114     creating build
2021-02-02T14:26:35,114     creating build/lib.linux-x86_64-3.9
...

UPDATING build/lib.linux-x86_64-3.9/matplotlib/_version.py
2021-02-02T14:26:35,248     set build/lib.linux-x86_64-3.9/matplotlib/_version.py to '3.2.2'
2021-02-02T14:26:35,248     running build_ext
2021-02-02T14:26:35,422     building 'matplotlib.ft2font' extension
2021-02-02T14:26:35,422     creating build/temp.linux-x86_64-3.9
2021-02-02T14:26:35,423     creating build/temp.linux-x86_64-3.9/src
2021-02-02T14:26:35,423     gcc -pthread -B /home/tebw2/.miniconda3/envs/pip_test19/compiler_compat -Wl,--sysroot=/ -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -Wall -fPIC -O2 -isystem /home/tebw2/.miniconda3/envs/pip_test19/include -fPIC -O2 -isystem /home/tebw2/.miniconda3/envs/pip_test19/include -fPIC -DFREETYPE_BUILD_TYPE=system -DPY_ARRAY_UNIQUE_SYMBOL=MPL_matplotlib_ft2font_ARRAY_API -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -D__STDC_FORMAT_MACROS=1 -Iextern/agg24-svn/include -I/home/tebw2/.miniconda3/envs/pip_test19/lib/python3.9/site-packages/numpy/core/include -I/home/tebw2/.miniconda3/envs/pip_test19/include/python3.9 -c src/checkdep_freetype2.c -o build/temp.linux-x86_64-3.9/src/checkdep_freetype2.o
2021-02-02T14:26:35,441     src/checkdep_freetype2.c:3:6: error: #error "FreeType version 2.3 or higher is required. You may set the MPLLOCALFREETYPE environment variable to 1 to let Matplotlib download it."
2021-02-02T14:26:35,442          #error "FreeType version 2.3 or higher is required. \
2021-02-02T14:26:35,442           ^~~~~
2021-02-02T14:26:35,442     src/checkdep_freetype2.c:10:10: error: #include expects "FILENAME" or <FILENAME>
2021-02-02T14:26:35,442      #include FT_FREETYPE_H
2021-02-02T14:26:35,442               ^~~~~~~~~~~~~
2021-02-02T14:26:35,443     src/checkdep_freetype2.c:15:9: note: #pragma message: Compiling with FreeType version FREETYPE_MAJOR.FREETYPE_MINOR.FREETYPE_PATCH.
2021-02-02T14:26:35,443      #pragma message("Compiling with FreeType version " \
2021-02-02T14:26:35,443              ^~~~~~~
2021-02-02T14:26:35,443     src/checkdep_freetype2.c:18:4: error: #error "FreeType version 2.3 or higher is required. You may set the MPLLOCALFREETYPE environment variable to 1 to let Matplotlib download it."
2021-02-02T14:26:35,443        #error "FreeType version 2.3 or higher is required. \
2021-02-02T14:26:35,443         ^~~~~
2021-02-02T14:26:35,444     error: command '/usr/bin/gcc' failed with exit code 1
2021-02-02T14:26:35,493 ERROR: Command errored out with exit status 1: /home/tebw2/.miniconda3/envs/pip_test19/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-yex4uuan/matplotlib_d0905bdbb1154c048c67297a2621a796/setup.py'"'"'; __file__='"'"'/tmp/pip-install-yex4uuan/matplotlib_d0905bdbb1154c048c67297a2621a796/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-uc41zjxg/install-record.txt --single-version-externally-managed --compile --install-headers /home/tebw2/.miniconda3/envs/pip_test19/include/python3.9/matplotlib Check the logs for full command output.
2021-02-02T14:26:35,493 Exception information:
2021-02-02T14:26:35,493 Traceback (most recent call last):
2021-02-02T14:26:35,493   File "/home/tebw2/.miniconda3/envs/pip_test19/lib/python3.9/site-packages/pip/_internal/req/req_install.py", line 840, in install
2021-02-02T14:26:35,493     success = install_legacy(
2021-02-02T14:26:35,493   File "/home/tebw2/.miniconda3/envs/pip_test19/lib/python3.9/site-packages/pip/_internal/operations/install/legacy.py", line 86, in install
2021-02-02T14:26:35,493     raise LegacyInstallFailure
2021-02-02T14:26:35,493 pip._internal.operations.install.legacy.LegacyInstallFailure
2021-02-02T14:26:35,493 
2021-02-02T14:26:35,493 During handling of the above exception, another exception occurred:
2021-02-02T14:26:35,493 
2021-02-02T14:26:35,493 Traceback (most recent call last):
2021-02-02T14:26:35,493   File "/home/tebw2/.miniconda3/envs/pip_test19/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 224, in _main
2021-02-02T14:26:35,493     status = self.run(options, args)
2021-02-02T14:26:35,493   File "/home/tebw2/.miniconda3/envs/pip_test19/lib/python3.9/site-packages/pip/_internal/cli/req_command.py", line 180, in wrapper
2021-02-02T14:26:35,493     return func(self, options, args)
2021-02-02T14:26:35,493   File "/home/tebw2/.miniconda3/envs/pip_test19/lib/python3.9/site-packages/pip/_internal/commands/install.py", line 394, in run
2021-02-02T14:26:35,493     installed = install_given_reqs(
2021-02-02T14:26:35,493   File "/home/tebw2/.miniconda3/envs/pip_test19/lib/python3.9/site-packages/pip/_internal/req/__init__.py", line 82, in install_given_reqs
2021-02-02T14:26:35,493     requirement.install(
2021-02-02T14:26:35,493   File "/home/tebw2/.miniconda3/envs/pip_test19/lib/python3.9/site-packages/pip/_internal/req/req_install.py", line 858, in install
2021-02-02T14:26:35,493     six.reraise(*exc.parent)
2021-02-02T14:26:35,493   File "/home/tebw2/.miniconda3/envs/pip_test19/lib/python3.9/site-packages/pip/_vendor/six.py", line 703, in reraise
2021-02-02T14:26:35,493     raise value
2021-02-02T14:26:35,493   File "/home/tebw2/.miniconda3/envs/pip_test19/lib/python3.9/site-packages/pip/_internal/operations/install/legacy.py", line 74, in install
2021-02-02T14:26:35,493     runner(
2021-02-02T14:26:35,493   File "/home/tebw2/.miniconda3/envs/pip_test19/lib/python3.9/site-packages/pip/_internal/utils/subprocess.py", line 271, in runner
2021-02-02T14:26:35,493     call_subprocess(
2021-02-02T14:26:35,493   File "/home/tebw2/.miniconda3/envs/pip_test19/lib/python3.9/site-packages/pip/_internal/utils/subprocess.py", line 240, in call_subprocess
2021-02-02T14:26:35,493     raise InstallationError(exc_msg)
2021-02-02T14:26:35,493 pip._internal.exceptions.InstallationError: Command errored out with exit status 1: /home/tebw2/.miniconda3/envs/pip_test19/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-yex4uuan/matplotlib_d0905bdbb1154c048c67297a2621a796/setup.py'"'"'; __file__='"'"'/tmp/pip-install-yex4uuan/matplotlib_d0905bdbb1154c048c67297a2621a796/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-uc41zjxg/install-record.txt --single-version-externally-managed --compile --install-headers /home/tebw2/.miniconda3/envs/pip_test19/include/python3.9/matplotlib Check the logs for full command output.

If you have datetime issues can you open a bug report?

The datetime issues are internal to our package, I think (due to interactions between matplotlib and pandas) that we just don’t have time to diagnose at the moment. As and when we have chance to go through I will file a bug report if appropriate.

The issue here seems to be just that there’s no wheel available for matplotlib 3.2 on Python 3.9, and it won’t build from source. Would it be possible to provide wheels to resolve this?

I don’t know anything about our wheels process, except that 3.2 was built before py 3.9 existed.

Your issue in your above build is that your freetype is too old. You can read about this here: Installation Guide — Matplotlib 3.3.4 documentation

Try setting the MPLLOCALFREETYPE environment variable to 1.

Thanks for your reply. I can see that would solve my problem locally, but it would be likely that our users would face the same issue when installing via pip. So unfortunately that doesn’t really solve the issue.

1 Like

I’m not sure what the chances of someone building a py3.9 wheel for <3.3.0 are.

3.3.0 had some known issues with pandas and dates. I would still encourage you to try and fix the underlying problem as it is likely not that difficult. and/or was fixed in 3.3.1, so you only need exclude 3.3.0, not pin to be less than…

Also see: Matplotlib 3.3 compatibility fixups by TomAugspurger · Pull Request #35393 · pandas-dev/pandas · GitHub

Great, thanks for these! I hadn’t twigged that there was a known issue with 3.3.0 - I’m not sure we’ve tried again since these were pushed. Will have a look into it.

I also hadn’t appreciated how long ago it was that 3.2 was superseded - fully appreciate that you can’t keep maintaining older versions. Cheers.

I’m not saying we can’t. I’m not sure what our wheel policy is!

1 Like