我在安装 matplotlib 时遇到问题

i have a problem with installing matplotlib

我在 windows 10 机器上安装 matplotlib 时遇到问题

PS C:\Users\moham> pip install matplotlib
Collecting matplotlib
  Using cached matplotlib-3.4.3.tar.gz (37.9 MB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: cycler>=0.10 in c:\users\moham\appdata\local\programs\python\python310\lib\site-packages (from matplotlib) (0.11.0)
Requirement already satisfied: kiwisolver>=1.0.1 in c:\users\moham\appdata\local\programs\python\python310\lib\site-packages (from matplotlib) (1.3.2)
Requirement already satisfied: numpy>=1.16 in c:\users\moham\appdata\local\programs\python\python310\lib\site-packages (from matplotlib) (1.21.3)
Requirement already satisfied: pillow>=6.2.0 in c:\users\moham\appdata\local\programs\python\python310\lib\site-packages (from matplotlib) (8.4.0)
Requirement already satisfied: pyparsing>=2.2.1 in c:\users\moham\appdata\local\programs\python\python310\lib\site-packages (from matplotlib) (3.0.3)
Requirement already satisfied: python-dateutil>=2.7 in c:\users\moham\appdata\local\programs\python\python310\lib\site-packages (from matplotlib) (2.8.2)
Requirement already satisfied: six>=1.5 in c:\users\moham\appdata\local\programs\python\python310\lib\site-packages (from python-dateutil>=2.7->matplotlib) (1.16.0)
Building wheels for collected packages: matplotlib
  Building wheel for matplotlib (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\Users\moham\AppData\Local\Programs\Python\Python310\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\moham\AppData\Local\Temp\pip-install-flrd8ddj\matplotlib_7091154205ba4de6adb6e99636c201f9\setup.py'"'"'; __file__='"'"'C:\Users\moham\AppData\Local\Temp\pip-install-flrd8ddj\matplotlib_7091154205ba4de6adb6e99636c201f9\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\moham\AppData\Local\Temp\pip-wheel-hj9g1qjt'
       cwd: C:\Users\moham\AppData\Local\Temp\pip-install-flrd8ddj\matplotlib_7091154205ba4de6adb6e99636c201f9\
  Complete output (553 lines):

  Edit setup.cfg to change the build options; suppress output with --quiet.

  BUILDING MATPLOTLIB
    matplotlib: yes [3.4.3]
        python: yes [3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC
                    v.1929 64 bit (AMD64)]]
      platform: yes [win32]
         tests: no  [skipping due to configuration]
        macosx: no  [Mac OS-X only]

  C:\Users\moham\AppData\Local\Programs\Python\Python310\lib\site-packages\setuptools\__init__.py:148: SetuptoolsDeprecationWarning: setup_requires is deprecated. Supply build dependencies using PEP 517 pyproject.toml build-requires.
    warnings.warn(
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-3.10
  copying lib\pylab.py -> build\lib.win-amd64-3.10

这里还有很多行 但在中间的某个地方它到达了这个:

 
  ----------------------------------------
  ERROR: Failed building wheel for matplotlib
  Running setup.py clean for matplotlib
Failed to build matplotlib
Installing collected packages: matplotlib
    Running setup.py install for matplotlib ... error
    ERROR: Command errored out with exit status 1:
     command: 'C:\Users\moham\AppData\Local\Programs\Python\Python310\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\moham\AppData\Local\Temp\pip-install-flrd8ddj\matplotlib_7091154205ba4de6adb6e99636c201f9\setup.py'"'"'; __file__='"'"'C:\Users\moham\AppData\Local\Temp\pip-install-flrd8ddj\matplotlib_7091154205ba4de6adb6e99636c201f9\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\moham\AppData\Local\Temp\pip-record-wj_x0r_i\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\moham\AppData\Local\Programs\Python\Python310\Include\matplotlib'
         cwd: C:\Users\moham\AppData\Local\Temp\pip-install-flrd8ddj\matplotlib_7091154205ba4de6adb6e99636c201f9\
    Complete output (553 lines):

    Edit setup.cfg to change the build options; suppress output with --quiet.

    BUILDING MATPLOTLIB
      matplotlib: yes [3.4.3]
          python: yes [3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC
                      v.1929 64 bit (AMD64)]]
        platform: yes [win32]
           tests: no  [skipping due to configuration]
          macosx: no  [Mac OS-X only]

    C:\Users\moham\AppData\Local\Programs\Python\Python310\lib\site-packages\setuptools\__init__.py:148: SetuptoolsDeprecationWarning: setup_requires is deprecated. Supply build dependencies using PEP 517 pyproject.toml build-requires.
      warnings.warn(
    running install
    C:\Users\moham\AppData\Local\Programs\Python\Python310\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
      warnings.warn(
    running build
    running build_py
    creating build\lib.win-amd64-3.10
    copying lib\pylab.py -> build\lib.win-amd64-3.10

还有很多行 并以此结尾:

    copying lib\matplotlib\mpl-data\images\zoom_to_rect_large.png -> build\lib.win-amd64-3.10\matplotlib\mpl-data\images    copying lib\matplotlib\mpl-data\fonts\ttf\DejaVuSansDisplay.ttf -> build\lib.win-amd64-3.10\matplotlib\mpl-data\fonts\ttf
    copying lib\matplotlib\mpl-data\fonts\afm\pagdo8a.afm -> build\lib.win-amd64-3.10\matplotlib\mpl-data\fonts\afm
    copying lib\matplotlib\mpl-data\images\matplotlib.pdf -> build\lib.win-amd64-3.10\matplotlib\mpl-data\images
    copying lib\matplotlib\backends\web_backend\css\page.css -> build\lib.win-amd64-3.10\matplotlib\backends\web_backend\css
    copying lib\matplotlib\mpl-data\fonts\ttf\STIXSizFourSymBol.ttf -> build\lib.win-amd64-3.10\matplotlib\mpl-data\fonts\ttf
    UPDATING build\lib.win-amd64-3.10\matplotlib\_version.py
    set build\lib.win-amd64-3.10\matplotlib\_version.py to '3.4.3'
    running build_ext
    error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
    Building freetype in build\freetype-2.6.1
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\moham\AppData\Local\Programs\Python\Python310\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\moham\AppData\Local\Temp\pip-install-flrd8ddj\matplotlib_7091154205ba4de6adb6e99636c201f9\setup.py'"'"'; __file__='"'"'C:\Users\moham\AppData\Local\Temp\pip-install-flrd8ddj\matplotlib_7091154205ba4de6adb6e99636c201f9\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\moham\AppData\Local\Temp\pip-record-wj_x0r_i\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\moham\AppData\Local\Programs\Python\Python310\Include\matplotlib' Check the logs for full command output.
PS C:\Users\moham>

................................................ ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... .........

最新稳定版为3.4.3。在 PyPI 上还有 no matplotlib wheel for 3.10。所以它尝试从源代码编译。为此,它需要 Microsoft Visual C++ 14.0 或更高版本。

不过你可以下载unofficial binary from Gohlke 或者,您可以使用 pipwin 从 Gohlke 安装它。请注意,依赖项可能仍然存在问题。

当然也可以降级到python3.9.