当我尝试在Windows 10上为python3.8安装matplotlib时,出现以下错误:
Collecting matplotlib
Using cached https://files.pythonhosted.org/packages/12/d1/7b12cd79c791348cb0c78ce6e7d16bd72992f13c9f1e8e43d2725a6d8adf/matplotlib-3.1.1.tar.gz
Requirement already satisfied: cycler>=0.10 in c:\python\lib\site-packages (from matplotlib) (0.10.0)
Requirement already satisfied: kiwisolver>=1.0.1 in c:\python\lib\site-packages (from matplotlib) (1.1.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in c:\python\lib\site-packages (from matplotlib) (2.4.4)
Requirement already satisfied: python-dateutil>=2.1 in c:\python\lib\site-packages (from matplotlib) (2.8.1)
Requirement already satisfied: numpy>=1.11 in c:\python\lib\site-packages (from matplotlib) (1.17.3)
Requirement already satisfied: six in c:\python\lib\site-packages (from cycler>=0.10->matplotlib) (1.13.0)
Requirement already satisfied: setuptools in c:\python\lib\site-packages (from kiwisolver>=1.0.1->matplotlib) (41.6.0)
Installing collected packages: matplotlib
Running setup.py install for matplotlib ... error
ERROR: Command errored out with exit status 1:
command: 'c:\python\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\meaw2\\AppData\\Local\\Temp\\pip-install-i9gp1wy9\\matplotlib\\setup.py'"'"'; __file__='"'"'C:\\Users\\meaw2\\AppData\\Local\\Temp\\pip-install-i9gp1wy9\\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 'C:\Users\meaw2\AppData\Local\Temp\pip-record-fl6iymv4\install-record.txt' --single-version-externally-managed --compile
cwd: C:\Users\meaw2\AppData\Local\Temp\pip-install-i9gp1wy9\matplotlib\
Complete output (505 lines):
================================================================================
Edit setup.cfg to change the build options
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]
OPTIONAL SUBPACKAGES
sample_data: yes [installing]
tests: no [skipping due to configuration]
OPTIONAL BACKEND EXTENSIONS
agg: yes [installing]
tkagg: yes [installing; run-time loading from Python Tcl/Tk]
macosx: no [Mac OS-X only]
OPTIONAL PACKAGE DATA
dlls: no [skipping due to configuration]
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -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 -Ic:\python\lib\site-packages\numpy\core\include -Ic:\python\include -Ic:\python\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /Tcsrc/checkdep_freetype2.c /Fobuild\temp.win32-3.8\Release\src/checkdep_freetype2.obj
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 14.0\\VC\\BIN\\cl.exe' failed with exit status 2
----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\python\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\meaw2\\AppData\\Local\\Temp\\pip-install-i9gp1wy9\\matplotlib\\setup.py'"'"'; __file__='"'"'C:\\Users\\meaw2\\AppData\\Local\\Temp\\pip-install-i9gp1wy9\\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 'C:\Users\meaw2\AppData\Local\Temp\pip-record-fl6iymv4\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output.
主要问题是使用python 3.8。卸载并安装python 3.7,它将正常运行。