在Python 3.8上安装Matplotlib时出错

时间:2019-10-25 11:22:23

标签: python matplotlib terminal macos-catalina python-3.8

已解决:在Mac上安装Xcode会安装所有缺少的Matplotlib依赖项,因此我能够通过终端成功安装Matplotlib。

我目前在Mac OS X Catalina上拥有Python 2.7和Python 3.8(已通过Python.org下载了.dmg)。我已经通过Terminal成功地安装了Numpy,以及通过Terminal在Python 2.7上成功地安装了Matplotlib,但是当我通过Terminal安装Matplotlib时,我总是得到两个错误代码。我曾尝试通过在线研究中的故障排除方法通过终端使用不同的输入变体,但无济于事。

输入:

pip3 install matplotlib

输出(错误1):

ERROR: Command errored out with exit status 1:
 command: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/6l/48hzctr50x9gg5rv9zzc5jl40000gn/T/pip-install-k3_jyhbb/matplotlib/setup.py'"'"'; __file__='"'"'/private/var/folders/6l/48hzctr50x9gg5rv9zzc5jl40000gn/T/pip-install-k3_jyhbb/matplotlib/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/6l/48hzctr50x9gg5rv9zzc5jl40000gn/T/pip-record-9nz4sjf0/install-record.txt --single-version-externally-managed --compile
     cwd: /private/var/folders/6l/48hzctr50x9gg5rv9zzc5jl40000gn/T/pip-install-k3_jyhbb/matplotlib/
Complete output (509 lines):
IMPORTANT WARNING:
    pkg-config is not installed.
    matplotlib may not be able to find some of its dependencies
================================================================================
Edit setup.cfg to change the build options

输出(错误2):

  gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -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/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/core/include -I/Library/Frameworks/Python.framework/Versions/3.8/include/python3.8 -c src/checkdep_freetype2.c -o build/temp.macosx-10.9-x86_64-3.8/src/checkdep_freetype2.o
src/checkdep_freetype2.c:1:10: fatal error: 'ft2build.h' file not found
#include <ft2build.h>
         ^~~~~~~~~~~~
1 error generated.
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/6l/48hzctr50x9gg5rv9zzc5jl40000gn/T/pip-install-k3_jyhbb/matplotlib/setup.py'"'"'; __file__='"'"'/private/var/folders/6l/48hzctr50x9gg5rv9zzc5jl40000gn/T/pip-install-k3_jyhbb/matplotlib/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/6l/48hzctr50x9gg5rv9zzc5jl40000gn/T/pip-record-9nz4sjf0/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.

2 个答案:

答案 0 :(得分:0)

我可以使用非官方的软件包解决此问题,您可以下载然后here 并确保安装了需求,您也可以在链接上找到它们,然后使用以下命令安装每个软件包:

pip install "SomePackage-1.0-py2.py3-none-any.whl"

答案 1 :(得分:-2)

  

在python 2.7上安装了matplotlib

当前版本的matplotlib需要Python> = 3.6,因此这可能是您面临的挑战。但我认为第一个错误是问题所在所在-好像您缺少所需的第三方依赖关系。您可以在这里获得: https://matplotlib.org/3.1.1/users/installing.html#building-on-macos

如果不起作用,可以将您的输出粘贴到注释中。