ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

PyArrow 安装指南详解:从 PyPI/Conda 安装到 conda-forge 三件套包的深度解析

PyArrow 安装指南详解:从 PyPI/Conda 安装到 conda-forge 三件套包的深度解析 PyArrow 安装指南详解从 PyPI/Conda 安装到 conda-forge 三件套包的深度解析【免费下载链接】arrowApache Arrow is the universal columnar format and multi-language toolbox for fast data interchange and in-memory analytics项目地址: https://gitcode.com/GitHub_Trending/arrow3/arrow本文基于 Apache Arrow 官方文档 install.rst 展开系统讲解 PyArrow 的官方安装方式、系统/Python 版本兼容范围、可选依赖与 Windows 时区数据库配置要点并结合 python/CMakeLists.txt、python/pyproject.toml 等仓库源码深入解析 conda-forge 上pyarrow-core、pyarrow、pyarrow-all三个包的功能划分及其与底层 Arrow C 组件的对应关系。读完后你可以选择正确的安装渠道、理解三个 conda 包的取舍逻辑、按需在 Conda 环境中自定义组件组合并正确处理 Windows 时区相关的边界问题。一、系统兼容性与 Python 版本支持官方文档明确说明PyArrow 在 Windows、macOS 和各种 Linux 发行版上被定期构建和测试并强烈建议使用 64 位系统。关于 Python 版本文档当前表述为PyArrow 目前兼容 Python 3.11、3.12、3.13 和 3.14。从源码可以进一步印证这一版本边界。python/pyproject.toml 中声明了硬性下限requires-python 3.11同时classifiers中列出了 3.11 至 3.15 以及 Free Threading无 GIL 实验性支持标记python/pyproject.tomlclassifiers [ Programming Language :: Python :: 3.11, Programming Language :: Python :: 3.12, Programming Language :: Python :: 3.13, Programming Language :: Python :: 3.14, Programming Language :: Python :: 3.15, Programming Language :: Python :: Free Threading :: 2 - Beta, ]可以推断当前开发主线已将支持下限固定在 3.113.15 及 free-threading 构建属于较新的开发目标实际可用版本请以发布渠道中的 wheel 为准。二、使用 Conda 安装推荐方式官方推荐大多数用户通过 conda-forge 安装最新版 PyArrowconda install -c conda-forge pyarrow文档中特别提示pyarrow这个 conda-forge 包对多数用户是正确选择但同时存在最小变体pyarrow-core和完整变体pyarrow-all二者可能更适合特定场景。三者的详细差异见下文conda-forge 三包差异一节。三、使用 Pip 安装从 PyPI 安装最新版支持 Windows、Linux、macOSpip install pyarrow文档列出两个平台相关的注意事项都是实际部署中高频踩坑点Windows 导入问题若在 Windows 上使用 pip 安装的 wheel 时遇到导入错误可能还需要安装最新的 Visual C Redistributable for Visual Studio微软官方提供文档附有链接指引。Linux 上的 pip 版本要求在 Linux 上需要pip 19.0才能正确检测到预编译的二进制包manylinux wheel。旧版 pip 会回退到源码构建缺少 Arrow C 依赖时会失败。关于 PyPI 上的构建体系python/pyproject.toml 显示当前 sdist 的构建后端为scikit-build-core并要求requires [ scikit-build-core 1.0, cython 3.1, numpy2.0, setuptools_scm[toml]8, ] build-backend scikit_build_core.build这说明从源码构建 PyArrow 需要完整的 C 编译工具链与 Cython ≥ 3.1对于只想装来用的用户pip 预编译 wheel 是更稳妥的路径。夜间构建包nightly与完全从源码安装的步骤文档指向 Python 开发文档python-development章节本文不展开。四、可选依赖与运行时配套包官方文档列出的可选依赖依赖最低版本作用NumPy2.0 或更高NumPy 数组与 Arrow 数组互转pandas2.2.2 或更高DataFrame 互转cffi未指定动态库接口此外PyArrow 与以下包兼容fsspec文件系统抽象、以及用于时区的pytz、dateutil或tzdata包。从仓库的测试依赖清单 python/requirements-test.txt 可以看到上游实际验证过的配套版本组合cffi hypothesis packaging pandas; python_version 3.15 pandas3.1.0.dev0; python_version 3.15 pytest pytest-xdist pytz这印证了文档中 pandas 的版本约束低版本 Python 用稳定版 pandasPython 3.15 开发线改用 pandas 3.1 开发版并额外引入了hypothesis、pytest-xdist等测试框架依赖。4.1 Windows 上的 tzdata 处理文档中关于时区数据库的说明值得逐条掌握Linux 与 macOSArrow 直接使用操作系统提供的时区数据库无需额外配置。Windows MSVC或较新 MinGW GCC13 及以上使用 Windows 时区数据库覆盖大多数预编译包无需额外设置。Windows Clang/libc 构建需要用户自行提供 IANA 时区数据库。文档给出两条路径按 C 文档中的下载时区数据库步骤操作见 ci/scripts/download_tz_database.sh 对应的 C 侧说明或使用已弃用的工具函数pyarrow.util.download_tzdata_on_windows()。源码层面python/pyarrow/util.py 中该函数已明确标注弃用def download_tzdata_on_windows(): r Download and extract latest IANA timezone database into the location expected by Arrow which is %USERPROFILE%\Downloads\tzdata. .. deprecated:: 24.0.0 This function is deprecated and will be removed in a future version. PyArrow now uses the operating systems timezone database on Windows. 函数默认将 IANA 时区数据库解压到%USERPROFILE%\Downloads\tzdata若数据库放在其他位置需通过已弃用的pa.set_timezone_db_path(custom_path)设置自定义路径。python/pyarrow/config.pxi 中可以看到该函数自 24.0.0 起发出FutureWarning底层通过CGlobalOptions.timezone_db_path在Initialize时注入。对应的行为测试分别在 python/pyarrow/tests/test_util.py非 Windows 平台调用该函数应抛错和 python/pyarrow/tests/test_misc.py非 Windows 平台调用set_timezone_db_path应报错中验证。pip 安装写 ORC 文件时的已知问题与解决办法文档原文 note安装pip install tzdata设置环境变量TZDIR path\to\.venv\Lib\site-packages\tzdata\。可以用以下命令定位tzdata的安装位置import tzdata print(tzdata.__file__) # path\to\.venv\Lib\site-packages\tzdata\__init__.py五、conda-forge 三包差异pyarrow-core / pyarrow / pyarrow-all这是本文的核心技术点。文档指出在 conda-forge 上PyArrow 被拆分为三个独立包功能层级不同而 PyPI 只发布单一的pyarrow包。拆分的目的是让多数用户安装最小体积的pyarrow为特殊场景提供极简的pyarrow-core为需要完整功能的用户保留pyarrow-all即历史上 conda-forge 的pyarrow包。5.1 各包包含的功能pyarrow-core包含数据核心data计算库pyarrow.computeIOioIPCpyarrow.ipc文件系统pyarrow.fs。文档注明云文件系统S3、GCS 等计划在未来版本移入pyarrow但本地文件系统将保留在pyarrow-core中文件格式Arrow/Feather、JSON、CSV、ORC不含 Parquetpyarrow在此基础上追加Aceropyarrow.aceroDatasetpyarrow.datasetParquetpyarrow.parquetSubstraitpyarrow.substraitpyarrow-all再追加Flight 与 Flight SQLpyarrow.flightGandivapyarrow.gandiva5.2 功能-包对应总表组件对应 C 库pyarrow-corepyarrowpyarrow-allCorepyarrow-core✓✓✓Parquetlibparquet✓✓Datasetlibarrow-dataset✓✓Acerolibarrow-acero✓✓Substraitlibarrow-substrait✓✓Flightlibarrow-flight✓Flight SQLlibarrow-flight-sql✓Gandivalibarrow-gandiva✓5.3 与源码中 CMake 开关的对应关系上表并非纸面约定而是直接映射到构建系统的组件开关。python/CMakeLists.txt 中通过define_option将 PyArrow 各集成模块与 Arrow C 的同名开关绑定define_option(ACERO Build the PyArrow Acero integration ARROW_ACERO) define_option(CUDA Build the PyArrow CUDA support ARROW_CUDA) define_option(DATASET Build the PyArrow Dataset integration ARROW_DATASET) define_option(FLIGHT Build the PyArrow Flight integration ARROW_FLIGHT) define_option(GANDIVA Build the PyArrow Gandiva integration ARROW_GANDIVA) define_option(ORC Build the PyArrow ORC integration ARROW_ORC) define_option(PARQUET Build the PyArrow Parquet integration ARROW_PARQUET) define_option(SUBSTRAIT Build the PyArrow Substrait integration ARROW_SUBSTRAIT) define_option(AZURE Build the PyArrow Azure integration ARROW_AZURE) define_option(GCS Build the PyArrow GCS integration ARROW_GCS) define_option(S3 Build the PyArrow S3 integration ARROW_S3) define_option(HDFS Build the PyArrow HDFS integration ARROW_HDFS)从源码结构看各模块还存在编译期依赖强制例如启用 Substrait 会连带开启 Dataset启用 Dataset 会连带开启 Aceropython/CMakeLists.txt# enforce module dependencies if(PYARROW_BUILD_SUBSTRAIT) set(PYARROW_BUILD_DATASET ON) endif() if(PYARROW_BUILD_DATASET) set(PYARROW_BUILD_ACERO ON) endif()这与文档表格中pyarrow 包包含 Acero Dataset Parquet Substrait的组合逻辑一致——Dataset 依赖 Acero 查询执行引擎因此二者总是一起出现。当对应 Arrow C 库缺失时CMake 会直接报错如if(NOT ARROW_DATASET) message(FATAL_ERROR You must build Arrow C with ARROW_DATASETON)python/CMakeLists.txt。六、创建自定义组件组合文档Creating A Custom Selection小节给出的实操建议如果你明确知道自己需要哪些组件可以只安装pyarrow-core并叠加所需功能包从而精确控制安装体积。示例 1core Parquet——安装pyarrow-core并叠加libparquetconda install -c conda-forge pyarrow-core libparquet示例 2标准 pyarrow Flight RPCconda install -c conda-forge pyarrow libarrow-flight由此可以总结一条通用的自定义公式pyarrow-core 按需叠加 { libparquet, libarrow-dataset, libarrow-acero, libarrow-substrait, libarrow-flight, libarrow-flight-sql, libarrow-gandiva }由于 Dataset/Acero/Substrait 之间的依赖关系见上一节 CMake 强制逻辑选择libarrow-dataset时 Acero 会作为其依赖被自动带上实际安装体积以 conda 求解结果为准。七、安装方式选择速查场景推荐方式说明日常分析、已有 Conda 环境conda install -c conda-forge pyarrow文档推荐的主路径追求最小安装体积conda install -c conda-forge pyarrow-core [ 功能库 ]不含 Parquet/Dataset/Flight需要全部组件Flight、Gandiva 等conda install -c conda-forge pyarrow-all即历史上的完整 pyarrow纯 pip 环境、无需 C 构建工具链pip install pyarrow注意 Linux 需 pip ≥ 19.0Windows 可能需要 VC Redistributable需要 nightly 或源码构建参见 Python 开发文档需 C 工具链、Cython ≥ 3.1、scikit-build-core八、小结PyArrow 的安装体系可以用一句话概括PyPI 给开箱即用conda-forge 给精确组合。官方文档给出的兼容范围Python ≥ 3.11、64 位系统优先、三个 conda 包的功能分层表以及 Windows 时区数据库的分场景处理方式构成了日常使用与部署的主要决策依据而 python/CMakeLists.txt 中的组件开关与依赖强制规则则解释了这些功能分层在构建系统上的真实来源。对于需要控制依赖体积的生产环境建议按pyarrow-core 按需功能库的方式裁剪对于需要 Flight RPC 或 Gandiva 的场景则选择pyarrow-all或叠加libarrow-flight等对应组件。【免费下载链接】arrowApache Arrow is the universal columnar format and multi-language toolbox for fast data interchange and in-memory analytics项目地址: https://gitcode.com/GitHub_Trending/arrow3/arrow创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表