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

使用pip安装pycryptodome3.4.3报错/usr/bin/ld: cannot find -lpython3.7m的原因及解决方法

解决pip安装pycryptodome 3.4.3时出现/usr/bin/ld: cannot find -lpython3.7m错误

问题背景

在Python 3.7.4环境下执行pip install pycryptodome==3.4.3时,遭遇链接器报错,核心错误信息为:

/usr/bin/ld: cannot find -lpython3.7m

完整报错的关键片段如下:

Collecting pycryptodome==3.4.3
Using cached https://files.pythonhosted.org/packages/45/ef/4514a01be3d8f5383cd12fc5612ffd8a2508ac7e7ff6bde2da708e71c9a3/pycryptodome-3.4.3.tar.gz
Installing collected packages: pycryptodome
Running setup.py install for pycryptodome ... error
...
gcc -pthread -shared -Wl,-z,relro -g build/temp.linux-x86_64-3.7/src/MD2.o -L/usr/lib64 -lpython3.7m -o build/lib.linux-x86_64-3.7/Crypto/Hash/_MD2.cpython-37m-x86_64-linux-gnu.so
/usr/bin/ld: cannot find -lpython3.7m
collect2: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1

错误原因

这个错误本质是系统链接器(ld)找不到Python 3.7的共享库文件。-lpython3.7m是链接器的参数,要求链接名为libpython3.7m.so的库——该库属于Python的开发包(包含编译所需的头文件和共享库),如果你的系统没有安装对应版本的Python开发包,或者库文件的路径未被链接器识别,就会触发这个错误。

解决步骤

1. 安装Python 3.7开发包(最常见解决方案)

根据你的Linux发行版,执行对应命令安装开发包:

  • CentOS/RHEL系列:
    sudo yum install python37-devel
    
  • Debian/Ubuntu系列:
    sudo apt update && sudo apt install python3.7-dev
    

安装完成后,重新运行pip安装命令:

pip install pycryptodome==3.4.3

2. 已安装开发包但仍报错:手动指定库路径

如果已经安装了开发包,但链接器仍找不到库,可能是库文件路径不在链接器默认搜索列表中。可以通过以下方式解决:

  • 临时设置链接器库路径:
    export LD_LIBRARY_PATH=/usr/lib64/python3.7/config-3.7m-x86_64-linux-gnu/:$LD_LIBRARY_PATH
    pip install pycryptodome==3.4.3
    
  • 或者在安装时直接传递库路径参数:
    pip install pycryptodome==3.4.3 --global-option=build_ext --global-option="-L/usr/lib64/python3.7/config-3.7m-x86_64-linux-gnu/"
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.08 16:42:48