Python3.11安装requests-kerberos时遇libgssapi_krb5.so找不到错误
安装requests-kerberos时libgssapi_krb5.so找不到的问题
问题描述
执行pip install requests-kerberos时触发以下错误:
OSError: python3/3.11.1/lib64:python3/3.11.1/lib:python3/3.11.1/lib64:python3/3.11.1/lib:python3/3.11.1/lib:python3/3.11.1/lib64:/libgssapi_krb5.so: cannot open shared object file: No such file or directory
已在../python/lib/目录下找到libgssapi_krb5.so文件,且将该路径添加至LD_LIBRARY_PATH环境变量,但问题仍未解决,当前使用Python 3.11.1版本。
完整错误日志:
Installing build dependencies ... done Running command Getting requirements to build wheel Traceback (most recent call last): File "my_area/python_tst/my_py/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module> main() File "my_area/python_tst/my_py/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main json_out['return_val'] = hook(**hook_input['kwargs']) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "my_area/python_tst/my_py/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel return hook(config_settings) ^^^^^^^^^^^^^^^^^^^^^ File "/tmp/pip-build-env-r4fyocus/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 341, in get_requires_for_build_wheel return self._get_build_requires(config_settings, requirements=['wheel']) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/pip-build-env-r4fyocus/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 323, in _get_build_requires self.run_setup() File "/tmp/pip-build-env-r4fyocus/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 338, in run_setup exec(code, locals()) File "<string>", line 206, in <module> File "python3/3.11.1/lib/python3.11/ctypes/__init__.py", line 376, in __init__ self._handle = _dlopen(self._name, mode) ^^^^^^^^^^^^^^^^^^^^^^^^^ OSError: python3/3.11.1/lib64:python3/3.11.1/lib:python3/3.11.1/lib64:python3/3.11.1/lib:python3/3.11.1/lib:python3/3.11.1/lib64:/libgssapi_krb5.so: cannot open shared object file: No such file or directory 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. full command: my_area/python_tst/my_py/bin/python3 my_area/python_tst/my_py/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py get_requires_for_build_wheel /tmp/tmpcq6mx3_f cwd: /tmp/pip-install-l9aynml0/gssapi_40233975a0f24def9d5db604f4e4b0bd Getting requirements to build wheel ... error error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> See above for output.
问题原因分析
- 环境变量未正确传递:临时设置的
LD_LIBRARY_PATH可能未被pip进程继承,或者设置后未生效(比如未重新加载配置文件)。 - 路径格式错误:
LD_LIBRARY_PATH需要添加的是库文件所在的目录路径,而非库文件本身;若添加的是文件路径会导致解析失败。 - 编译时未指定库路径:pip编译依赖包时,可能未读取到
LD_LIBRARY_PATH的设置,需要显式指定编译参数。 - 系统缺少Kerberos开发依赖:底层的Kerberos开发库未安装,导致编译过程无法正确链接库文件。
- 库架构不匹配:
libgssapi_krb5.so的架构(32位/64位)与Python运行环境的架构不一致,导致无法加载。
解决方法
确认LD_LIBRARY_PATH生效:
- 在执行pip的终端中运行
echo $LD_LIBRARY_PATH,检查是否包含../python/lib/目录。 - 若为临时设置,确保在同一个终端执行pip;若为持久化设置(如写入
~/.bashrc或~/.profile),执行source ~/.bashrc(对应shell配置文件)或重新打开终端使其生效。
- 在执行pip的终端中运行
显式指定编译库路径:
执行以下命令强制编译时指向目标库目录:LDFLAGS="-L$(realpath ../python/lib)" pip install requests-kerberos或同时指定CFLAGS:
CFLAGS="-I$(realpath ../python/include)" LDFLAGS="-L$(realpath ../python/lib)" pip install requests-kerberos安装系统级Kerberos开发包:
- Debian/Ubuntu系统:
sudo apt-get install libkrb5-dev - CentOS/RHEL系统:
sudo yum install krb5-devel
- Debian/Ubuntu系统:
检查库与Python架构匹配:
- 查看库文件架构:
file ../python/lib/libgssapi_krb5.so - 查看Python架构:
python3 -c "import platform; print(platform.architecture())"
若两者架构不一致,需更换对应架构的库文件或Python环境。
- 查看库文件架构:
内容的提问来源于stack exchange,提问作者Saeed isa
相关产品推荐
相关产品推荐

