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

PyInstaller打包依赖PyArrow的Windows单文件应用DLL加载失败求助

PyInstaller打包PyArrow依赖的Windows单文件应用时,pyarrow.lib导入失败(DLL加载错误)

问题摘要

使用PyInstaller打包依赖PyArrow的Windows单文件.exe应用,运行时因导入pyarrow.lib出现DLL加载失败错误,无法正常启动。

版本/系统信息

  • Python 3.11.9
  • PyInstaller 5.13.2
  • PyArrow 16.1.0
  • Windows 10.0.19045

详细说明

开发依赖PyArrow的小型应用,在Conda环境qt-env中执行以下PyInstaller打包命令:

pyinstaller --onefile --clean --debug "all" --add-data "logo.svg;." --hiddenimport "pkg_resources.extern" data_app.py

其中logo.svg为应用加载的图片,构建过程仅出现以下警告:

WARNING: Hidden import "pyarrow.compat" not found!

运行生成的data_app.exe时失败,报错堆栈:

# pyarrow.lib not found in PYZ
Traceback (most recent call last):
  File "data_app.py", line 4, in <module>
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "pyarrow\__init__.py", line 65, in <module>
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 676, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 573, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1233, in create_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
ImportError: DLL load failed while importing lib: The specified procedure could not be found.

构建过程中发现PyInstaller加载的钩子文件路径为:

INFO: Loading module hook 'hook-pyarrow.py' from 'C:\\Users\\user\\anaconda3\\envs\\qt-env\\Lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'

该钩子文件为2020年的旧版本,且--additional-hooks-dir无法覆盖默认钩子,因此修改默认hook-pyarrow.py为最新版本内容:

from PyInstaller.utils.hooks import collect_submodules, collect_data_files, collect_dynamic_libs

hiddenimports = collect_submodules('pyarrow', filter=lambda x: "tests" not in x)
datas = collect_data_files('pyarrow')
binaries = collect_dynamic_libs('pyarrow')

修改后构建无pyarrow.compat相关警告,但运行时仍出现相同报错。

验证pyarrow.lib本身正常,执行以下代码无错误:

import pyarrow.lib as _lib

print(_lib.__file__)

输出路径:

C:\Users\user\anaconda3\envs\qt-env\Lib\site-packages\pyarrow\lib.cp311-win_amd64.pyd

尝试直接指定pyarrow.lib文件作为隐藏导入:

--hiddenimport "C:\Users\user\anaconda3\envs\qt-env\Lib\site-packages\pyarrow\lib.cp311-win_amd64.pyd"

但生成的exe仍报错。

补充信息:\build\data_app\localpycs\pyarrow目录内容:

interchange
parquet
vendored
acero.pyc
benchmark.pyc
cffi.pyc
compute.pyc
conftest.pyc
csv.pyc
cuda.pyc
dataset.pyc
feather.pyc
flight.pyc
fs.pyc
ipc.pyc
json.pyc
jvm.pyc
orc.pyc
pandas_compat.pyc
substrait.pyc
types.pyc
util.pyc
_compute_docstrings.pyc
_generated_version.pyc
__init__.pyc

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 15:14:51