正在修复CentOS 6.4的Python2.7上的“警告:找不到GMP或MPIR库;未生成Crypto.PublickKey.\u fastmath”错误

2024-04-27 13:39:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在运行一个带有Python 2.7的CentOS 6.4服务器(通过PythonBrew脚本安装)

我通过“yum install gmp”安装了gmp 和python devel通过“yum install python devel”安装(但适用于python 2.6系列)

我试图在我的服务器上安装pycrypto,但它给了我

warning: GMP or MPIR library not found; Not building Crypto.PublickKey._fastmath

有什么方法可以让pip“认可”我的gmp安装吗?

谢谢:D


Tags: installor服务器脚本librarydevelwarningcentos
3条回答

我在Centos 6.4上尝试使用pip在系统级安装Fabric时遇到了上述错误。(Fabric使用pycrypto)。

warning: GMP or MPIR library not found; Not building Crypto.PublickKey._fastmath

我就是这样让它工作的:

yum install gmp-devel
sudo pip uninstall ecdsa pycrypto paramiko fabric 
# clear out the pip build dirs
rm -rf /tmp/pip-*
# make sure the directory containing libgmp.so.3 is on the python path
export LD_LIBRARY_PATH="/usr/lib64:$LD_LIBRARY_PATH"  
pip install fabric 

以下是我在CentOS服务器上创建的一个步骤(序列假设您不是根用户):

LIBGMP安装

首先,在主目录中的某个位置设置并安装libgmp,如下所示:

./configure prefix=$HOME
make
make install prefix=$HOME

这将创建一个~/lib、一个~/include和一个~/share目录(如果还不存在的话)。

然后,在.bashrc中添加以下行:

export LD_LIBRARY_PATH=$HOME/lib:/usr/local/lib:$LD_LIBRARY_PATH

做一个”。~/.bashrc“强制执行更改。

PYCRYPTO编译和安装

我们需要手动处理安装过程。 首先,我们可以下载pycrypto,如下所示:

然后我们需要欺骗配置“一点”:

cd pycrypto-26
./configure --includedir=$HOME/include
  • 编辑文件cd src/config.h并修改 定义:

    define将DECL MPZ POWM 0改为1

    define将DECL MPZ POWM SEC 1改为0

    #define用LIBGMP 1代替0

  • 然后通过搜索关键字“_fastmath”编辑setup.py文件 并确保Extension()声明如下所示:

    Extension("Crypto.PublicKey._fastmath",
              include_dirs=['/home/<yourhome>/include','src/','/usr/include/'],
              library_dirs=['/home/<yourhome>/lib'],
              libraries=['gmp'],
              sources=["src/_fastmath.c"]),
    

最后,使用以下命令构建pycrypto:

python setup.py build

你应该在轨迹的某个地方看到下面一行:

...
building 'Crypto.PublicKey._fastmath' extension
...

然后您可以执行“python setup.py安装”,或者,如果您喜欢pip:

cd ..
pip install ./pycrypto-2.6

那么在执行python中的以下行时,应该不会出错:

>>> from Crypto.PublicKey import _fastmath
>>> import Crypto.Random
>>> _fastmath.HAVE_DECL_MPZ_POWM_SEC
1

你可能也需要安装gmp-devel。这将为pycrypto提供使用libgmp构建所需的头。

在Ubuntu上,我只安装了libgmp10。我在尝试安装pycrypto时遇到了同样的警告。在安装了Ubuntu包libgmp dev之后,警告消失了,构建脚本指示它正在使用_fastmath扩展。

如果您已经安装了不带fastmath的pycrypto,那么可以使用-I标志重新安装它,例如

sudo pip install -I pycrypto

相关问题 更多 >