【问题标题】:Python, Error while installing matplotlibPython,安装 matplotlib 时出错
【发布时间】:2021-02-07 13:02:54
【问题描述】:

操作系统:Windows 10

Python 版本:3.9.0

错误代码:

ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output. 

我试过了:

python -m pip install -U pip
python -m pip install -U matplotlib

没用。

然后我尝试了:

pip install --upgrade setuptools

没有解决问题。

我在 SO 上读到,也许如果我以管理员模式打开 shell,它可以解决问题,但它也不起作用。

我看到有人提到此错误代码的 ez-setup。我安装了它,但也没有用。

不知道是不是有事,但是我的C目录是这样的:

C:\Users\METİNUSTA

它有一个大写的 i 字符,有时会导致应用程序出现问题。我无法更改它,因为我使用的是学校的 Windows 密钥,它不允许我进行任何更改。因此,我在 D: 上安装了 python。

这里还有我的点子列表以获取更多信息:

ez-setup    0.9
flake8      3.8.4
mccabe      0.6.1
pip         20.2.4
pycodestyle 2.6.0
pyflakes    2.2.0
setuptools  50.3.2
wheel       0.35.1

最后是我在 windows powershell 上得到的整个错误日志:

    ERROR: Command errored out with exit status 1:
     command: 'd:\python\python39\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\METİNUSTA\\AppData\\Local\\Temp\\pip-install-8iv10tb_\\matplotlib\\setup.py'"'"'; __file__='"'"'C:\\Users\\METİNUSTA\\AppData\\Local\\Temp\\pip-install-8iv10tb_\\matplotlib\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\METİNUSTA\AppData\Local\Temp\pip-pip-egg-info-elosrn6m'
         cwd: C:\Users\METİNUSTA\AppData\Local\Temp\pip-install-8iv10tb_\matplotlib\
    Complete output (99 lines):
      WARNING: Missing build requirements in pyproject.toml for numpy>=1.15 from https://files.pythonhosted.org/packages/bf/e8/15aea783ea72e2d4e51e3ec365e8dc4a1a32c9e5eb3a6d695b0d58e67cdd/numpy-1.19.2.zip#sha256=0d310730e1e793527065ad7dde736197b705d0e4c9999775f212b03c44a8484c.
      WARNING: The project does not specify a build backend, and pip cannot fall back to setuptools without 'setuptools>=40.8.0' and 'wheel'.
        ERROR: Command errored out with exit status 1:
         command: 'd:\python\python39\python.exe' 'd:\python\python39\lib\site-packages\pip\_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\METNUS~1\AppData\Local\Temp\tmpqz3brme_'
             cwd: C:\Users\METİNUSTA\AppData\Local\Temp\pip-wheel-l2wpf1i8\numpy
        Complete output (49 lines):
        Error in sitecustomize; set PYTHONVERBOSE for traceback:
        SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xdd in position 0: unexpected end of data (sitecustomize.py, line 21)
        Running from numpy source directory.
        setup.py:470: UserWarning: Unrecognized setuptools command, proceeding with generating Cython sources and expanding templates
          run_build = parse_setuppy_commands()
        Error in sitecustomize; set PYTHONVERBOSE for traceback:
        SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xdd in position 0: unexpected end of data (sitecustomize.py, line 21)
        Processing numpy/random\_bounded_integers.pxd.in
        Processing numpy/random\bit_generator.pyx
        Traceback (most recent call last):
          File "C:\Users\METİNUSTA\AppData\Local\Temp\pip-wheel-l2wpf1i8\numpy\tools\cythonize.py", line 59, in process_pyx
            from Cython.Compiler.Version import version as cython_version
        ModuleNotFoundError: No module named 'Cython'

        During handling of the above exception, another exception occurred:

        Traceback (most recent call last):
          File "C:\Users\METİNUSTA\AppData\Local\Temp\pip-wheel-l2wpf1i8\numpy\tools\cythonize.py", line 235, in <module>
            main()
          File "C:\Users\METİNUSTA\AppData\Local\Temp\pip-wheel-l2wpf1i8\numpy\tools\cythonize.py", line 231, in main
            find_process_files(root_dir)
          File "C:\Users\METİNUSTA\AppData\Local\Temp\pip-wheel-l2wpf1i8\numpy\tools\cythonize.py", line 222, in find_process_files
            process(root_dir, fromfile, tofile, function, hash_db)
          File "C:\Users\METİNUSTA\AppData\Local\Temp\pip-wheel-l2wpf1i8\numpy\tools\cythonize.py", line 188, in process
            processor_function(fromfile, tofile)
          File "C:\Users\METİNUSTA\AppData\Local\Temp\pip-wheel-l2wpf1i8\numpy\tools\cythonize.py", line 64, in process_pyx
            raise OSError('Cython needs to be installed in Python as a module')
        OSError: Cython needs to be installed in Python as a module
        Cythonizing sources
        Traceback (most recent call last):
          File "d:\python\python39\lib\site-packages\pip\_vendor\pep517\_in_process.py", line 280, in <module>
            main()
          File "d:\python\python39\lib\site-packages\pip\_vendor\pep517\_in_process.py", line 263, in main
            json_out['return_val'] = hook(**hook_input['kwargs'])
          File "d:\python\python39\lib\site-packages\pip\_vendor\pep517\_in_process.py", line 133, in prepare_metadata_for_build_wheel
            return hook(metadata_directory, config_settings)
          File "d:\python\python39\lib\site-packages\setuptools\build_meta.py", line 161, in prepare_metadata_for_build_wheel
            self.run_setup()
          File "d:\python\python39\lib\site-packages\setuptools\build_meta.py", line 253, in run_setup
            super(_BuildMetaLegacyBackend,
          File "d:\python\python39\lib\site-packages\setuptools\build_meta.py", line 145, in run_setup
            exec(compile(code, __file__, 'exec'), locals())
          File "setup.py", line 499, in <module>
            setup_package()
          File "setup.py", line 479, in setup_package
            generate_cython()
          File "setup.py", line 274, in generate_cython
            raise RuntimeError("Running cythonize failed!")
        RuntimeError: Running cythonize failed!
        ----------------------------------------
    ERROR: Command errored out with exit status 1: 'd:\python\python39\python.exe' 'd:\python\python39\lib\site-packages\pip\_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\METNUS~1\AppData\Local\Temp\tmpqz3brme_' Check the logs for full command output.
    Traceback (most recent call last):
      File "d:\python\python39\lib\site-packages\setuptools\installer.py", line 126, in fetch_build_egg
        subprocess.check_call(cmd)
      File "d:\python\python39\lib\subprocess.py", line 373, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['d:\\python\\python39\\python.exe', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', 'C:\\Users\\METNUS~1\\AppData\\Local\\Temp\\tmppoh8r2c9', '--quiet', 'numpy>=1.15']' 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\METİNUSTA\AppData\Local\Temp\pip-install-8iv10tb_\matplotlib\setup.py", line 242, in <module>
        setup(  # Finally, pass this all along to distutils to do the heavy lifting.
      File "d:\python\python39\lib\site-packages\setuptools\__init__.py", line 152, in setup
        _install_setup_requires(attrs)
      File "d:\python\python39\lib\site-packages\setuptools\__init__.py", line 147, in _install_setup_requires
        dist.fetch_build_eggs(dist.setup_requires)
      File "d:\python\python39\lib\site-packages\setuptools\dist.py", line 673, in fetch_build_eggs
        resolved_dists = pkg_resources.working_set.resolve(
      File "d:\python\python39\lib\site-packages\pkg_resources\__init__.py", line 764, in resolve
        dist = best[req.key] = env.best_match(
      File "d:\python\python39\lib\site-packages\pkg_resources\__init__.py", line 1049, in best_match
        return self.obtain(req, installer)
      File "d:\python\python39\lib\site-packages\pkg_resources\__init__.py", line 1061, in obtain
        return installer(requirement)
      File "d:\python\python39\lib\site-packages\setuptools\dist.py", line 732, in fetch_build_egg
        return fetch_build_egg(self, req)
      File "d:\python\python39\lib\site-packages\setuptools\installer.py", line 128, in fetch_build_egg
        raise DistutilsError(str(e)) from e
    distutils.errors.DistutilsError: Command '['d:\\python\\python39\\python.exe', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', 'C:\\Users\\METNUS~1\\AppData\\Local\\Temp\\tmppoh8r2c9', '--quiet', 'numpy>=1.15']' returned non-zero exit status 1.

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

    BUILDING MATPLOTLIB
      matplotlib: yes [3.3.2]
          python: yes [3.9.0 (tags/v3.9.0:9cf6752, Oct  5 2020, 15:34:40) [MSC
                      v.1927 64 bit (AMD64)]]
        platform: yes [win32]
     sample_data: yes [installing]
           tests: no  [skipping due to configuration]
          macosx: no  [Mac OS-X only]

    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

【问题讨论】:

  • matplotlib 尚未为 3.9 版制作轮子,因此您的 python 尝试从源代码构建它。你应该降级到 python 3.8 然后一切都应该工作
  • 非常感谢,请您添加您的评论作为答案吗?所以我可以标记为已解决。

标签: python matplotlib pip


【解决方案1】:

Matplotlib 没有适用于 python 版本 3.10 的轮子。 如果尝试在 3.10 版本的 python 中安装 matplotlib 通过

pip install matplotlib

结果:错误:为 matplotlib (setup.py)..error 构建轮子

Matplotlib 依赖得到满足,如下:

cycler = 0.10 
kiwisolver = 1.0.1
numpy = 1.16 
pillow = 6.2.0 
pyparsing = 2.2.1
six = 1.5 
python-dateutil = 2.7

尝试升级 pip 并安装 matplotlib

 python -m pip install -U pip
 python -m pip install -U matplotlib

成功安装 pip-21.3.1 再次它没有安装 Matplotlib。

因此将 Python 版本降低到 3.9 并安装了 Matplotlib。对于为 Matplotlib 定义的 Python 版本高达 3.9 的轮子,请务必使用 Python 3.9 并确保 pip 已升级到可用版本,安装 matplotlib 不会有问题

【讨论】:

  • 这并不能真正回答问题。如果您有其他问题,可以点击 提问。要在此问题有新答案时收到通知,您可以follow this question。一旦你有足够的reputation,你也可以add a bounty 来引起对这个问题的更多关注。 - From Review
【解决方案2】:

从源代码安装它(Python >= 3.9.2):

git clone git://github.com/matplotlib/matplotlib.git

并通过以下方式构建和安装:

cd matplotlib
python -mpip install .

如果您希望能够在开发分支发生变化时跟随它,只需将最后一步替换为:

python -mpip install -e .

来源和更多信息在这里:https://matplotlib.org/stable/faq/installing_faq.html#install-from-git

【讨论】:

    【解决方案3】:

    编辑: matplotlib 现在已经发布了适用于 python 3.9 的轮子,所以 pip install --upgrade matplotlib 应该可以工作了。

    原始答案

    matplotlib 尚未为 3.9 版制作轮子,因此您的 python 尝试从源代码构建它。你应该降级到 python 3.8 然后一切都应该工作

    【讨论】:

    • 仅供参考,以下是相关 PR,将为 Python 3.9 添加轮子:github.com/matplotlib/matplotlib/pull/18842。请注意,从源代码构建应该可以工作,但在 Windows 上,设置构建工具链可能需要一些工作。
    • 如何查看哪些轮子可用于 matplotlib?
    • 对于 Python ^3.9.2:请在下面考虑我的回答
    【解决方案4】:
    1. python -m pip install --upgrade pip

    2. pip install matplotlib==3.3.1

    为我工作。

    【讨论】:

      【解决方案5】:

      这是因为 matplotlib 没有 3.9 轮子..

      为了方便使用matplotlib,可以安装anaconda。 在 anaconda 环境 matplotlib 中,默认情况下,numpy 和 pandas 可用于安装在 Anaconda 中的 Python。 或者您可以使用较低版本的 Python。

      【讨论】:

        猜你喜欢
        • 2021-02-20
        • 2023-03-03
        • 1970-01-01
        • 2012-10-06
        • 1970-01-01
        • 2016-02-04
        • 1970-01-01
        • 2018-02-18
        相关资源
        最近更新 更多