使用 CentOS 6.4 在 Python 2.7 上修复“警告:未找到 GMP 或 MPIR 库;未构建 Crypto.PublickKey._fastmath”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17319033/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fixing "warning: GMP or MPIR library not found; Not building Crypto.PublickKey._fastmath" error on Python 2.7 with CentOS 6.4
提问by user269334
I'm running a CentOS 6.4 server with Python 2.7 (installed via PythonBrew script)
我正在使用 Python 2.7 运行 CentOS 6.4 服务器(通过 PythonBrew 脚本安装)
I have gmp installed via 'yum install gmp' and python-devel installed via 'yum install python-devel' (but it's for python 2.6 series)
我通过“yum install gmp”安装了 gmp,通过“yum install python-devel”安装了 python-devel(但它适用于 python 2.6 系列)
I'm trying to install pycrypto on my server, but it's giving me
我正在尝试在我的服务器上安装 pycrypto,但它给了我
warning: GMP or MPIR library not found; Not building Crypto.PublickKey._fastmath
Is there any way to make pip 'recognize' my gmp installation?
有什么办法可以让 pip '识别'我的 gmp 安装吗?
Thanks : D
感谢:D
回答by Paul
You probably need gmp-devel installed, too. This gives pycrypto the headers it needs to build using libgmp.
您可能也需要安装 gmp-devel。这为 pycrypto 提供了使用 libgmp 构建所需的头文件。
On Ubuntu, I only had libgmp10 installed. I hit the same warning when trying to install pycrypto. After installing the Ubuntu package libgmp-dev, the warning went away and the build script indicated it was using the _fastmath extension.
在 Ubuntu 上,我只安装了 libgmp10。我在尝试安装 pycrypto 时遇到了同样的警告。安装 Ubuntu 软件包 libgmp-dev 后,警告消失了,构建脚本表明它正在使用 _fastmath 扩展。
If you already installed pycrypto without _fastmath, you can reinstall it with the -I flag, e.g.
如果您已经安装了没有 _fastmath 的 pycrypto,您可以使用 -I 标志重新安装它,例如
sudo pip install -I pycrypto
sudo pip install -I pycrypto
回答by lai
Here is a step-by-step I've just made up on my CentOS server (the sequence assumes you're not root):
这是我刚刚在我的 CentOS 服务器上编写的分步说明(该序列假设您不是 root):
LIBGMP INSTALL
安装 LIBGMP
Firstly, setup and install libgmp somewhere in your home directory, as follows:
首先,在您的主目录中的某处设置并安装 libgmp,如下所示:
./configure prefix=$HOME
make
make install prefix=$HOME
This will create a ~/lib, a ~/include and a ~/share directory if not existing already.
这将创建一个 ~/lib、一个 ~/include 和一个 ~/share 目录(如果尚不存在)。
Then, add the following line to your .bashrc:
然后,将以下行添加到您的 .bashrc:
export LD_LIBRARY_PATH=$HOME/lib:/usr/local/lib:$LD_LIBRARY_PATH
Do a ". ~/.bashrc" to enforce your changes.
执行“. ~/.bashrc”以强制执行您的更改。
PYCRYPTO BUILD & INSTALL
PYCRYPTO 构建和安装
We need to deal with the install process manually. Firstly, we may download pycrypto as follows:
我们需要手动处理安装过程。首先,我们可以按如下方式下载pycrypto:
go into a directory where you store your sources:
cd ~/src
download pycrypto source archive:
curl -o pycrypto.tar.gz "https://pypi.python.org/packages/source/p/pycrypto/pycrypto-2.6.tar.gz#md5=88dad0a270d1fe83a39e0467a66a22bb"
uncompress + untar archive:
gunzip pycrypto.tar.gz tar xvf pycrypto.tar
进入存储源的目录:
cd ~/src
下载 pycrypto 源文件:
curl -o pycrypto.tar.gz " https://pypi.python.org/packages/source/p/pycrypto/pycrypto-2.6.tar.gz#md5=88dad0a270d1fe83a39e0467a66a22bb"
解压 + 解压存档:
gunzip pycrypto.tar.gz tar xvf pycrypto.tar
Then we need to cheat the configuration "a bit":
然后我们需要“一点”地欺骗配置:
cd pycrypto-26
./configure --includedir=$HOME/include
Edit the file cd src/config.h and amend the values for the definitions:
#define HAVE_DECL_MPZ_POWM 0 instead of 1
#define HAVE_DECL_MPZ_POWM_SEC 1 instead of 0
#define HAVE_LIBGMP 1 instead of 0
Then edit the setup.py file by searching for the keyword "_fastmath" and ensure that the Extension() declaration looks as per below:
Extension("Crypto.PublicKey._fastmath", include_dirs=['/home/<yourhome>/include','src/','/usr/include/'], library_dirs=['/home/<yourhome>/lib'], libraries=['gmp'], sources=["src/_fastmath.c"]),
编辑文件 cd src/config.h 并修改定义的值:
#define HAVE_DECL_MPZ_POWM 0 而不是 1
#define HAVE_DECL_MPZ_POWM_SEC 1 而不是 0
#define HAVE_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"]),
Finally, build pycrypto with:
最后,使用以下命令构建 pycrypto:
python setup.py build
You should see somewhere in the trace the following line:
您应该在跟踪中的某处看到以下行:
...
building 'Crypto.PublicKey._fastmath' extension
...
You can then do a "python setup.py install" or, if like me you prefer pip:
然后,您可以执行“python setup.py install”,或者,如果像我一样您更喜欢 pip:
cd ..
pip install ./pycrypto-2.6
Then you should get no error when executing the following lines from python:
然后从 python 执行以下行时应该不会出错:
>>> from Crypto.PublicKey import _fastmath
>>> import Crypto.Random
>>> _fastmath.HAVE_DECL_MPZ_POWM_SEC
1
回答by Joe J
I got the above error when trying to install Fabric at the system level on Centos 6.4 using pip. (Fabric uses pycrypto).
尝试使用 pip 在 Centos 6.4 上的系统级别安装 Fabric 时出现上述错误。(织物使用 pycrypto)。
warning: GMP or MPIR library not found; Not building Crypto.PublickKey._fastmath
This is how I got it working:
这就是我让它工作的方式:
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
回答by Justin Rush
Just for anyone who runs across this in recent years, as I am sure there are/will be some. I was able to easily fix this issue on my Debian Jessie install by running the following command.
仅适用于近年来遇到此问题的任何人,因为我相信会有/将会有一些。通过运行以下命令,我能够在我的 Debian Jessie 安装上轻松解决此问题。
$ sudo apt-get install python-dev
Then try your install again. In my case I was trying to install ansible via pip with the following command. Also for those to be able to come across this post with same scenario.
然后再次尝试安装。就我而言,我试图使用以下命令通过 pip 安装 ansible。同样对于那些能够在相同场景中遇到这篇文章的人。
$ sudo pip install ansible
The output should now be the following.
输出现在应该如下所示。
Successfully installed pycrypto
Cleaning up...
I hope this helps someone down the road! - justin
我希望这可以帮助有人在路上!- 贾斯汀
回答by advdev
You are missing the C++ libraries to build this. Install VS 2017 https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2017
您缺少构建它的 C++ 库。安装 VS 2017 https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2017