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

PyInstaller编译Python工具报错:libmkl_intel_thread.so缺omp_get_num_procs符号

解决PyInstaller编译后运行出现libmkl_intel_thread.so: undefined symbol: omp_get_num_procs的问题

这问题我在Manjaro上打包依赖MKL的Python工具时遇到过,本质是MKL库依赖的OpenMP符号没被正确链接到打包后的程序里,给你几个实用的解决办法:

1. 确保系统安装了OpenMP库并正确链接

Manjaro默认可能没装完整的OpenMP依赖,先补装:

sudo pacman -S openmp

打包时可以显式告诉PyInstaller包含OpenMP库,修改PyInstaller命令:

pyinstaller --add-binary "/usr/lib/libomp.so:." your_script.py

2. 手动收集MKL相关依赖(推荐用.spec文件)

PyInstaller有时候自动收集MKL的库不全,我们可以手动指定。先生成.spec文件:

pyinstaller your_script.py

然后编辑生成的your_script.spec文件,添加以下内容来完整收集MKL的所有组件:

from PyInstaller.utils.hooks import collect_all

# 收集MKL的所有数据、二进制文件和隐式导入
mkl_datas, mkl_binaries, mkl_hiddenimports = collect_all('mkl')
datas += mkl_datas
binaries += mkl_binaries
hiddenimports += mkl_hiddenimports

之后用.spec文件重新打包:

pyinstaller your_script.spec

3. 运行时临时指定OpenMP库加载路径

如果打包后还是报错,可以在运行程序前设置LD_PRELOAD环境变量,强制加载系统的OpenMP库:

LD_PRELOAD=/usr/lib/libomp.so ./your_compiled_executable

要是觉得每次输入麻烦,可以把这个命令写到一个shell脚本里,方便工作组的人直接运行。

额外注意点

  • 虽然你说构建目录命名为'uild'不影响,但建议还是改成规范的build,避免后续可能出现的路径解析小问题;
  • 如果你的Python环境是conda创建的,记得激活环境后再打包,确保PyInstaller能找到conda环境里的MKL依赖;
  • 可以先运行python -c "import mkl; print(mkl.get_version_string())"确认MKL版本,确保和系统的OpenMP版本兼容。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 03:36:42