【问题标题】:Can't install matplotlib in a Python 3.10 venv无法在 Python 3.10 venv 中安装 matplotlib
【发布时间】:2021-10-20 20:23:02
【问题描述】:

我一直在关注这个教程:

https://code.visualstudio.com/docs/python/python-tutorial

  • 我创建并激活了一个新的 venv:d:\dev\python\.venv
  • 我用pip install -U pip更新了点子
  • 我用pip install wheel安装了轮子
  • 我用pip install -U setuptools升级了setuptools

现在,当我运行 python -m pip install matplotlib 时,会出现大量错误:

Collecting matplotlib
  Using cached matplotlib-3.4.3.tar.gz (37.9 MB)
  Preparing metadata (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'D:\Dev\Python\.venv\scripts\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\futur\\AppData\\Local\\Temp\\pip-install-ebo82l6e\\matplotlib_1d648b7683fc4253bd1e0efcfa4c8b68\\setup.py'"'"'; __file__='"'"'C:\\Users\\futur\\AppData\\Local\\Temp\\pip-install-ebo82l6e\\matplotlib_1d648b7683fc4253bd1e0efcfa4c8b68\\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'"'"'))' egg_info --egg-base 'C:\Users\futur\AppData\Local\Temp\pip-pip-egg-info-gyrvg9v_'
       cwd: C:\Users\futur\AppData\Local\Temp\pip-install-ebo82l6e\matplotlib_1d648b7683fc4253bd1e0efcfa4c8b68\     
  Complete output (248 lines):
    ERROR: Command errored out with exit status 1:
     command: 'D:\Dev\Python\.venv\scripts\python.exe' 'D:\Dev\Python\.venv\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py' build_wheel 'C:\Users\futur\AppData\Local\Temp\tmpg193i1cc'
         cwd: C:\Users\futur\AppData\Local\Temp\pip-wheel-n4amfybf\numpy_cc1bec4e42d0410f9c1a5efc1bf3f864
    Complete output (200 lines):
    setup.py:63: RuntimeWarning: NumPy 1.21.2 may not yet support Python 3.10.
      warnings.warn(
    Running from numpy source directory.
    C:\Users\futur\AppData\Local\Temp\pip-wheel-n4amfybf\numpy_cc1bec4e42d0410f9c1a5efc1bf3f864\tools\cythonize.py:69: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or 
check PEP 632 for potential alternatives
      from distutils.version import LooseVersion
    Processing numpy/random\_bounded_integers.pxd.in
    Processing numpy/random\bit_generator.pyx
    Processing numpy/random\mtrand.pyx
    Processing numpy/random\_bounded_integers.pyx.in
    Processing numpy/random\_common.pyx
    Processing numpy/random\_generator.pyx
    Processing numpy/random\_mt19937.pyx
    Processing numpy/random\_pcg64.pyx
    Processing numpy/random\_philox.pyx
    Processing numpy/random\_sfc64.pyx
    Cythonizing sources
    blas_opt_info:
    blas_mkl_info:
    No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
    customize MSVCCompiler
      libraries mkl_rt not found in ['D:\\Dev\\Python\\.venv\\lib', 'C:\\']
      NOT AVAILABLE

    blis_info:
      libraries blis not found in ['D:\\Dev\\Python\\.venv\\lib', 'C:\\']
      NOT AVAILABLE

    openblas_info:
      libraries openblas not found in ['D:\\Dev\\Python\\.venv\\lib', 'C:\\']
    get_default_fcompiler: matching types: '['gnu', 'intelv', 'absoft', 'compaqv', 'intelev', 'gnu95', 'g95', 'intelvem', 'intelem', 'flang']'
    customize GnuFCompiler
    Could not locate executable g77
    Could not locate executable f77
    customize IntelVisualFCompiler
    Could not locate executable ifort
    Could not locate executable ifl
    customize AbsoftFCompiler
    Could not locate executable f90
    customize CompaqVisualFCompiler
    Could not locate executable DF
    customize IntelItaniumVisualFCompiler
    Could not locate executable efl
    customize Gnu95FCompiler
    Could not locate executable gfortran
    Could not locate executable f95
    customize G95FCompiler
    Could not locate executable g95
    customize IntelEM64VisualFCompiler
    customize IntelEM64TFCompiler
    Could not locate executable efort
    Could not locate executable efc
    customize PGroupFlangCompiler
    Could not locate executable flang
    don't know how to compile Fortran code on platform 'nt'
      NOT AVAILABLE

    accelerate_info:
      NOT AVAILABLE

    atlas_3_10_blas_threads_info:
    Setting PTATLAS=ATLAS
      libraries tatlas not found in ['D:\\Dev\\Python\\.venv\\lib', 'C:\\']
      NOT AVAILABLE

    atlas_3_10_blas_info:
      libraries satlas not found in ['D:\\Dev\\Python\\.venv\\lib', 'C:\\']
      NOT AVAILABLE

    atlas_blas_threads_info:
    Setting PTATLAS=ATLAS
      libraries ptf77blas,ptcblas,atlas not found in ['D:\\Dev\\Python\\.venv\\lib', 'C:\\']
      NOT AVAILABLE

    atlas_blas_info:
      libraries f77blas,cblas,atlas not found in ['D:\\Dev\\Python\\.venv\\lib', 'C:\\']
      NOT AVAILABLE

    C:\Users\futur\AppData\Local\Temp\pip-wheel-n4amfybf\numpy_cc1bec4e42d0410f9c1a5efc1bf3f864\numpy\distutils\system_info.py:2026: UserWarning:
        Optimized (vendor) Blas libraries are not found.
        Falls back to netlib Blas library which has worse performance.
        A better performance should be easily gained by switching
        Blas library.
      if self._calc_info(blas):
    blas_info:
      libraries blas not found in ['D:\\Dev\\Python\\.venv\\lib', 'C:\\']
      NOT AVAILABLE

    C:\Users\futur\AppData\Local\Temp\pip-wheel-n4amfybf\numpy_cc1bec4e42d0410f9c1a5efc1bf3f864\numpy\distutils\system_info.py:2026: UserWarning:
        Blas (http://www.netlib.org/blas/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [blas]) or by setting
        the BLAS environment variable.
      if self._calc_info(blas):
    blas_src_info:
      NOT AVAILABLE

    C:\Users\futur\AppData\Local\Temp\pip-wheel-n4amfybf\numpy_cc1bec4e42d0410f9c1a5efc1bf3f864\numpy\distutils\system_info.py:2026: UserWarning:
        Blas (http://www.netlib.org/blas/) sources not found.
        Directories to search for the sources can be specified in the
        numpy/distutils/site.cfg file (section [blas_src]) or by setting
        the BLAS_SRC environment variable.
      if self._calc_info(blas):
      NOT AVAILABLE

    non-existing path in 'numpy\\distutils': 'site.cfg'
    lapack_opt_info:
    lapack_mkl_info:
      libraries mkl_rt not found in ['D:\\Dev\\Python\\.venv\\lib', 'C:\\']
      NOT AVAILABLE

    openblas_lapack_info:
      libraries openblas not found in ['D:\\Dev\\Python\\.venv\\lib', 'C:\\']
      NOT AVAILABLE

    openblas_clapack_info:
      libraries openblas,lapack not found in ['D:\\Dev\\Python\\.venv\\lib', 'C:\\']
      NOT AVAILABLE

    flame_info:
      libraries flame not found in ['D:\\Dev\\Python\\.venv\\lib', 'C:\\']
      NOT AVAILABLE

    atlas_3_10_threads_info:
    Setting PTATLAS=ATLAS
      libraries lapack_atlas not found in D:\Dev\Python\.venv\lib
      libraries tatlas,tatlas not found in D:\Dev\Python\.venv\lib
      libraries lapack_atlas not found in C:\
      libraries tatlas,tatlas not found in C:\
    <class 'numpy.distutils.system_info.atlas_3_10_threads_info'>
      NOT AVAILABLE

    atlas_3_10_info:
      libraries lapack_atlas not found in D:\Dev\Python\.venv\lib
      libraries satlas,satlas not found in D:\Dev\Python\.venv\lib
      libraries lapack_atlas not found in C:\
      libraries satlas,satlas not found in C:\
    <class 'numpy.distutils.system_info.atlas_3_10_info'>
      NOT AVAILABLE

    atlas_threads_info:
    Setting PTATLAS=ATLAS
      libraries lapack_atlas not found in D:\Dev\Python\.venv\lib
      libraries ptf77blas,ptcblas,atlas not found in D:\Dev\Python\.venv\lib
      libraries lapack_atlas not found in C:\
      libraries ptf77blas,ptcblas,atlas not found in C:\
    <class 'numpy.distutils.system_info.atlas_threads_info'>
      NOT AVAILABLE

    atlas_info:
      libraries lapack_atlas not found in D:\Dev\Python\.venv\lib
      libraries f77blas,cblas,atlas not found in D:\Dev\Python\.venv\lib
      libraries lapack_atlas not found in C:\
      libraries f77blas,cblas,atlas not found in C:\
    <class 'numpy.distutils.system_info.atlas_info'>
      NOT AVAILABLE

    lapack_info:
      libraries lapack not found in ['D:\\Dev\\Python\\.venv\\lib', 'C:\\']
      NOT AVAILABLE

    C:\Users\futur\AppData\Local\Temp\pip-wheel-n4amfybf\numpy_cc1bec4e42d0410f9c1a5efc1bf3f864\numpy\distutils\system_info.py:1858: UserWarning:
        Lapack (http://www.netlib.org/lapack/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [lapack]) or by setting
        the LAPACK environment variable.
      return getattr(self, '_calc_info_{}'.format(name))()
    lapack_src_info:
      NOT AVAILABLE

    C:\Users\futur\AppData\Local\Temp\pip-wheel-n4amfybf\numpy_cc1bec4e42d0410f9c1a5efc1bf3f864\numpy\distutils\system_info.py:1858: UserWarning:
        Lapack (http://www.netlib.org/lapack/) sources not found.
        Directories to search for the sources can be specified in the
        numpy/distutils/site.cfg file (section [lapack_src]) or by setting
        the LAPACK_SRC environment variable.
      return getattr(self, '_calc_info_{}'.format(name))()
      NOT AVAILABLE

    numpy_linalg_lapack_lite:
      FOUND:
        language = c
        define_macros = [('HAVE_BLAS_ILP64', None), ('BLAS_SYMBOL_SUFFIX', '64_')]

    Warning: attempted relative import with no known parent package
    C:\Program Files\Python310\lib\distutils\dist.py:274: UserWarning: Unknown distribution option: 'define_macros' 
      warnings.warn(msg)
    running bdist_wheel
    running build
    running config_cc
    unifing config_cc, config, build_clib, build_ext, build commands --compiler options
    running config_fc
    unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
    running build_src
    build_src
    building py_modules sources
    creating build
    creating build\src.win-amd64-3.10
    creating build\src.win-amd64-3.10\numpy
    creating build\src.win-amd64-3.10\numpy\distutils
    building library "npymath" sources
    error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/
    ----------------------------------------
    ERROR: Failed building wheel for numpy
  ERROR: Failed to build one or more wheels
  Traceback (most recent call last):
    File "D:\Dev\Python\.venv\lib\site-packages\setuptools\installer.py", line 75, in fetch_build_egg
      subprocess.check_call(cmd)
    File "C:\Program Files\Python310\lib\subprocess.py", line 369, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['D:\\Dev\\Python\\.venv\\scripts\\python.exe', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', 'C:\\Users\\futur\\AppData\\Local\\Temp\\tmp94tnb4kh', '--quiet', 'numpy>=1.16']' returned non-zero exit status 1.

  The above exception was the direct cause of the following exception:

  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\futur\AppData\Local\Temp\pip-install-ebo82l6e\matplotlib_1d648b7683fc4253bd1e0efcfa4c8b68\setup.py", line 258, in <module>
      setup(  # Finally, pass this all along to distutils to do the heavy lifting.
    File "D:\Dev\Python\.venv\lib\site-packages\setuptools\__init__.py", line 152, in setup
      _install_setup_requires(attrs)
    File "D:\Dev\Python\.venv\lib\site-packages\setuptools\__init__.py", line 147, in _install_setup_requires       
      dist.fetch_build_eggs(dist.setup_requires)
    File "D:\Dev\Python\.venv\lib\site-packages\setuptools\dist.py", line 806, in fetch_build_eggs
      resolved_dists = pkg_resources.working_set.resolve(
    File "D:\Dev\Python\.venv\lib\site-packages\pkg_resources\__init__.py", line 766, in resolve
      dist = best[req.key] = env.best_match(
    File "D:\Dev\Python\.venv\lib\site-packages\pkg_resources\__init__.py", line 1051, in best_match
      return self.obtain(req, installer)
    File "D:\Dev\Python\.venv\lib\site-packages\pkg_resources\__init__.py", line 1063, in obtain
      return installer(requirement)
    File "D:\Dev\Python\.venv\lib\site-packages\setuptools\dist.py", line 877, in fetch_build_egg
      return fetch_build_egg(self, req)
    File "D:\Dev\Python\.venv\lib\site-packages\setuptools\installer.py", line 77, in fetch_build_egg
      raise DistutilsError(str(e)) from e
  distutils.errors.DistutilsError: Command '['D:\\Dev\\Python\\.venv\\scripts\\python.exe', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', 'C:\\Users\\futur\\AppData\\Local\\Temp\\tmp94tnb4kh', '--quiet', 'numpy>=1.16']' returned non-zero exit status 1.

  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]

  ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/21/37/197e68df384ff694f78d687a49ad39f96c67b8d75718bc61503e1676b617/matplotlib-3.4.3.tar.gz#sha256=fc4f526dfdb31c9bd6b8ca06bf9fab663ca12f3ec9cdf4496fb44bc680140318 (from https://pypi.org/simple/matplotlib/) (requires-python:>=3.7). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

我想知道它是否与在 venv 中安装有关。

我查看了pyvenv.cfg 和include-system-site-packages 设置为false。我不确定这个值应该是多少。 Scripts目录有一些激活和去激活脚本,以及pip.exe、pip3.10.exe、pip3.exe、python.exe、pythonw.exe和wheel.exe。

.venv\Lib\site-packages 有以下内容:

distutils-precedence.pth
pip
pip-21.3.dist-info
pkg_resources
setuptools
setuptools-58.2.0.dist-info
wheel
wheel-0.37.0.dist-info
_distutils_hack
distutils-precedence.pth

有人知道问题出在哪里吗?我真的很想让这个工作。

非常感谢您的帮助。

【问题讨论】:

  • 可能与堆栈跟踪上方的error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/ 有关。

标签: python python-3.x matplotlib pip


【解决方案1】:

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

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

当然,你也可以降级到python3.9。

【讨论】:

  • 那么降级我的 Python 安装会是个好主意吗?
  • 是的,这也是一种选择。我编辑了我的答案。
  • 不错。我要使用 python-3.9.7-amd64,看起来这是最后一个稳定的 3.9 版本。
猜你喜欢
  • 1970-01-01
  • 2021-11-29
  • 2021-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-27
  • 1970-01-01
相关资源
最近更新 更多