You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows 10下pip安装poliastro时astropy编译失败求助

Windows 10下pip安装poliastro失败的解决步骤

问题详情

Windows 10系统,Python 3.11.5,pip已更新至最新版,安装poliastro时反复报错,核心错误提示:

error: command 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\bin\HostX86\x64\cl.exe' failed with exit code 2

完整错误片段:

error: command 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.36.32532\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
      [end of output]
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for astropy
Failed to build astropy
ERROR: Could not build wheels for astropy, which is required to install pyproject.toml-based projects

已尝试卸载重装astropy、在astropy已安装/未安装状态下安装poliastro、通过PyCharm安装,均无效。因内存不足无法使用Anaconda,C盘有2GB以上可用空间,其他Python包安装正常。

手动安装astropy v5时出现新错误,完整代码如下:

Microsoft Windows [Version 10.0.19045.3570]
(c) Microsoft Corporation. All rights reserved.

C:\Users\david>pip install astropy==5.0
Collecting astropy==5.0
  Using cached astropy-5.0.tar.gz (7.8 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [45 lines of output]
      astropy\wcs\setup_package.py:12: SetuptoolsDeprecationWarning: dep_util is Deprecated. Use functions from setuptools.modified instead.
      !!

              ********************************************************************************
              Please use `setuptools.modified` instead of `setuptools.dep_util`.

              By 2024-May-21, you need to update your project and remove deprecated calls
              or your builds will no longer be supported.

              See https://github.com/pypa/setuptools/pull/4069 for details.
              ********************************************************************************

      !!
        from setuptools.dep_util import newer_group
      Traceback (most recent call last):
        File "D:\Python\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
          main()
        File "D:\Python\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "D:\Python\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\david\AppData\Local\Temp\pip-build-env-p0aw2x30\overlay\Lib\site-packages\setuptools\build_meta.py", line 325, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\david\AppData\Local\Temp\pip-build-env-p0aw2x30\overlay\Lib\site-packages\setuptools\build_meta.py", line 295, in _get_build_requires
          self.run_setup()
        File "C:\Users\david\AppData\Local\Temp\pip-build-env-p0aw2x30\overlay\Lib\site-packages\setuptools\build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 68, in <module>
        File "C:\Users\david\AppData\Local\Temp\pip-build-env-p0aw2x30\overlay\Lib\site-packages\extension_helpers\_setup_helpers.py", line 67, in get_extensions
          ext_modules.extend(setuppkg.get_extensions())
                             ^^^^^^^^^^^^^^^^^^^^^^^^^
        File ".\astropy\modeling\setup_package.py", line 59, in get_extensions
          from jinja2 import Environment, FileSystemLoader
        File "C:\Users\david\AppData\Local\Temp\pip-build-env-p0aw2x30\overlay\Lib\site-packages\jinja2\__init__.py", line 33, in <module>
          from jinja2.environment import Environment, Template
        File "C:\Users\david\AppData\Local\Temp\pip-build-env-p0aw2x30\overlay\Lib\site-packages\jinja2\environment.py", line 15, in <module>
          from jinja2 import nodes
        File "C:\Users\david\AppData\Local\Temp\pip-build-env-p0aw2x30\overlay\Lib\site-packages\jinja2\nodes.py", line 19, in <module>
          from jinja2.utils import Markup
        File "C:\Users\david\AppData\Local\Temp\pip-build-env-p0aw2x30\overlay\Lib\site-packages\jinja2\utils.py", line 642, in <module>
          from markupsafe import Markup, escape, soft_unicode
      ImportError: cannot import name 'soft_unicode' from 'markupsafe' (C:\Users\david\AppData\Local\Temp\pip-build-env-p0aw2x30\overlay\Lib\site-packages\markupsafe\__init__.py)
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

分步解决方法

方法1:安装预编译的astropy二进制包

跳过本地编译步骤,直接用官方预编译的轮子:

  • 打开命令提示符(Win+R输入cmd回车)
  • 执行命令:pip install astropy --only-binary :all:
  • 待astropy安装完成后,执行pip install poliastro

方法2:修复MarkupSafe版本冲突(针对astropy5.0安装错误)

手动安装astropy5.0时的错误是因为MarkupSafe版本过高,需降级:

  • 卸载现有MarkupSafe:pip uninstall markupsafe -y
  • 安装兼容版本:pip install markupsafe==2.0.1
  • 安装astropy5.0:pip install astropy==5.0
  • 最后安装poliastro:pip install poliastro

方法3:检查Visual Studio编译工具配置

若编译错误仍存在,确认VS的C++编译组件完整:

  • 打开Microsoft Visual Studio 2022 Community
  • 点击顶部菜单「工具」→「获取工具和功能」
  • 在安装界面中,确保勾选「使用C的桌面开发」,重点确认「MSVC v143 - VS 2022 C x64/x86生成工具」已安装
  • 点击「修改」完成安装,重启电脑后再尝试安装

方法4:切换到Python 3.10版本(备选)

Python 3.11对部分旧库兼容性较差,可尝试降级:

  • 下载Python 3.10.x版本安装包
  • 安装时勾选「Add Python to PATH」
  • 更新pip:python -m pip install --upgrade pip
  • 执行pip install poliastro

内容的提问来源于stack exchange,提问作者Big Dave

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 19:45:02