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

Windows10下安装Python库Polars时遭遇PyArrow编译错误求助

问题描述

我在研究加速Pandas的替代方案Polars时,尝试通过pip install 'polars[all]'安装该库,遇到PyArrow编译错误。环境为Windows10,已安装Rust、Visual Studio Code 2022、CMake 3.24.0、Python 3.11.0。错误原因是CMake找不到Visual Studio 15 2017实例,导致无法构建PyArrow wheel,最终Polars安装失败。

环境信息:

python -c """import sys; print(sys.version)"""
3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]

python -c """import sys; print(sys.platform)"""
win32 # 我以为我的Windows10是64位的?

rustc --version
rustc 1.65.0 (897e37553 2022-11-02)

python --version
Python 3.11.0

C:/Program Files/CMake/bin/cmake --version
cmake version 3.24.0

CMake suite maintained and supported by Kitware (kitware.com/cmake).

错误日志片段:

.....
\Lib\site-packages\setuptools\_distutils\cmd.py", line 390, in spawn
          spawn(cmd, search_path, dry_run=self.dry_run)
        File "C:\Users\a126291\AppData\Local\Temp\pip-build-env-q2kfg6vo\overlay
\Lib\site-packages\setuptools\_distutils\spawn.py", line 38, in spawn
          log.info(subprocess.list2cmdline(cmd))
      Message: 'cmake -DARROW_BUILD_DIR=build -DCMAKE_BUILD_TYPE=release -DCMAKE
_INSTALL_LIBDIR=lib -DCMAKE_INSTALL_PREFIX=C:\\Users\\a126291\\AppData\\Local\\T
emp\\pip-install-z34b9m08\\pyarrow_e72f6907c8c34d73add7f6887f9ba9b4\\build\\dist
 "-DPYTHON_EXECUTABLE=C:\\Users\\a126291\\OneDrive - AmerisourceBergen(ABC)\\ven
v\\py311pol\\Scripts\\python.exe" "-DPython3_EXECUTABLE=C:\\Users\\a126291\\OneD
rive - AmerisourceBergen(ABC)\\venv\\py311pol\\Scripts\\python.exe" -DPYARROW_CX
XFLAGS= -DPYARROW_WITH_DATASET=off -DPYARROW_WITH_PARQUET_ENCRYPTION=off -DPYARR
OW_WITH_HDFS=off -G "Visual Studio 15 2017 Win64" C:\\Users\\a126291\\AppData\\L
ocal\\Temp\\pip-install-z34b9m08\\pyarrow_e72f6907c8c34d73add7f6887f9ba9b4\\pyar
row/src'
      Arguments: ()
      CMake Error at CMakeLists.txt:53 (project):
        Generator

          Visual Studio 15 2017 Win64

        could not find any instance of Visual Studio.

      -- Configuring incomplete, errors occurred!
      See also "C:/Users/a126291/AppData/Local/Temp/pip-install-z34b9m08/pyarrow
_e72f6907c8c34d73add7f6887f9ba9b4/build/cpp/CMakeFiles/CMakeOutput.log".
      -- Running CMake for PyArrow C++
      error: command 'C:\\Program Files\\CMake\\bin\\cmake.exe' failed with exit
 code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem wit
h pip.
  ERROR: Failed building wheel for pyarrow
Failed to build pyarrow
ERROR: Could not build wheels for pyarrow, which is required to install pyprojec
t.toml-based projects
解决方案

核心原因

安装polars[all]时需要依赖PyArrow,pip默认会尝试从源码编译PyArrow,而编译脚本指定了使用Visual Studio 15 2017 Win64作为CMake生成器,但你仅安装了Visual Studio 2022,导致CMake无法找到对应版本的构建工具。另外,sys.platform显示win32是Python在Windows平台的统一返回值,和系统位数无关,无需担心。

方法1:安装预编译的PyArrow Wheel(推荐)

直接让pip下载现成的预编译版本,跳过本地编译步骤:

  1. 单独安装PyArrow:
pip install pyarrow --only-binary :all:
  1. 再安装Polars[all]:
pip install 'polars[all]'

方法2:指定CMake使用Visual Studio 2022生成器

通过环境变量告诉CMake使用你已安装的VS2022:

  • CMD命令行:
set CMAKE_GENERATOR="Visual Studio 17 2022 Win64"
pip install 'polars[all]'
  • PowerShell:
$env:CMAKE_GENERATOR="Visual Studio 17 2022 Win64"
pip install 'polars[all]'

方法3:安装VS2017构建工具(不推荐)

如果你必须从源码编译PyArrow,可以通过VS Installer补充安装VS2017的构建组件:

  1. 打开Visual Studio Installer,选择修改Visual Studio 2022
  2. 在「单个组件」中找到并勾选「Visual Studio 2017生成工具」
  3. 完成安装后重新执行pip install 'polars[all]'

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 07:20:35