pip install pubnub 抛出 'gcc' 失败错误

pip install pubnub throws 'gcc' failed error

我正在尝试安装 pubnub 库,但在执行 pip install pubnub 时出现错误

Compiling support for Intel AES instructions
building 'Crypto.Hash._MD2' extension
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/src
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DLTC_NO_ASM -DHAVE_CPUID_H -Isrc/ -I/usr/include/python2.7 -c src/MD2.c -o build/temp.linux-x86_64-2.7/src/MD2.o
gcc -pthread -shared build/temp.linux-x86_64-2.7/src/MD2.o -L/usr/lib64 -lpython2.7 -o build/lib.linux-x86_64-2.7/Crypto/Hash/_MD2.so
/usr/bin/ld: cannot find -lpython2.7
collect2: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1

这些是我遵循的步骤

curl -O https://bootstrap.pypa.io/get-pip.py
sudo python27 get-pip.py
sudo yum install git
git clone https://github.com/pubnub/python && cd python/python
sudo update-alternatives --config python
sudo yum install python-devel
sudo yum install gcc

谢谢

您需要安装 Python 的头文件。具体操作方式取决于您的操作系统。

在 Debian 或 Ubuntu 上,例如

sudo apt-get install python-dev

应该做。

在 Fedora / CentOS / Red Hat 上,尝试

sudo yum install python-devel

这个问题的解决方案,我必须遵循这些步骤

ld -lpython2.7 --verbose

attempt to open /usr/x86_64-amazon-linux/lib64/libpython2.7.so failed
attempt to open /usr/x86_64-amazon-linux/lib64/libpython2.7.a failed
attempt to open /usr/local/lib64/libpython2.7.so failed
attempt to open /usr/local/lib64/libpython2.7.a failed
attempt to open /lib64/libpython2.7.so failed
attempt to open /lib64/libpython2.7.a failed
attempt to open /usr/lib64/libpython2.7.so failed
attempt to open /usr/lib64/libpython2.7.a failed
attempt to open /usr/x86_64-amazon-linux/lib/libpython2.7.so failed
attempt to open /usr/x86_64-amazon-linux/lib/libpython2.7.a failed
attempt to open /usr/lib64/libpython2.7.so failed
attempt to open /usr/lib64/libpython2.7.a failed
attempt to open /usr/local/lib/libpython2.7.so failed
attempt to open /usr/local/lib/libpython2.7.a failed
attempt to open /lib/libpython2.7.so failed
attempt to open /lib/libpython2.7.a failed
attempt to open /usr/lib/libpython2.7.so failed
attempt to open /usr/lib/libpython2.7.a failed

检查 ldconfig softlink 的 python 并找出它指向什么

ldconfig -p | grep python2.7

libpython2.7.so.1.0 (libc6,x86-64) => /usr/lib64/libpython2.7.so.1.0

这表明它正在寻找一个错误的软link,我把软link改成了这样

sudo ln -s /usr/lib64/libpython2.7.so.1.0 /usr/lib64/libpython2.7.so

然后不得不 运行 像这样

sudo /usr/local/bin/pip install pubnub -- Location of pip installed

工作得很好