Linux 下安装gmpy2

GMP(GNU Multiple Precision Arithmetic Library,即GNU高精度算术运算库),它是一个开源的高精度运算库,其中不但有普通的整数、实数、浮点数的高精度运算,还有随机数生成,尤其是提供了非常完备的数论中的运算接口,比如Miller-Rabin素数测试算法、大素数生成、欧几里德算法、求域中元素的逆、Jacobi符号、legendre符号等。
gmpy2是Python的一个扩展库,是对GMP的封装,它的前身是gmpy,经过其作者的调整和封装,使得gmpy2的使用大大简化。

-------

 

gmpy2是依赖GMP、MPFR、MPC三个库,故此在linux上安装前得先安装这3个库。

为了后续安装的方便,先建立2个文件夹。

mkdir -p $HOME/src
mkdir -p $HOME/static

 

安装GMP

GMP(The GNU Multiple Precision Arithmetic Library) is a free library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating-point numbers.
https://gmplib.org/

当前最新的是6.1.2

cd $HOME/src
wget https://gmplib.org/download/gmp/gmp-6.1.2.tar.bz2
tar -jxvf gmp-6.1.2.tar.bz2 && cd gmp-6.1.2
./configure --prefix=$HOME/static --enable-static --disable-shared --with-pic
make && make check && make install

 

安装MPFR

The MPFR library is a C library for multiple-precision floating-point computations with correct rounding.
http://www.mpfr.org/mpfr-current/#download
当前最新的是4.0.1 (请自己访问官网,替换成最新的版本号)

cd $HOME/src
wget http://www.mpfr.org/mpfr-current/mpfr-4.0.1.tar.bz2
tar -jxvf mpfr-4.0.1.tar.bz2 && cd mpfr-4.0.1
./configure --prefix=$HOME/static --enable-static --disable-shared --with-pic --with-gmp=$HOME/static
make && make check && make install

 

安装MPC

GNU MPC is a C library for the arithmetic of complex numbers with arbitrarily high precision and correct rounding of the result.
http://www.multiprecision.org/mpc/download.html (这里最新是1.0.3)
但当mpfr版本为4.x以上会报错Makefile:532: recipe for target 'mul.lo' failed

ftp://ftp.gnu.org/gnu/mpc/ 可以找到更新的1.1.0版本

cd $HOME/src
wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz
tar -zxvf mpc-1.1.0.tar.gz && cd mpc-1.1.0
./configure --prefix=$HOME/static --enable-static --disable-shared --with-pic --with-gmp=$HOME/static --with-mpfr=$HOME/static
make && make check && make install

 

安装gmpy2

github项目:https://github.com/aleaxit/gmpy

现在新的版本在执行python setup.py build_ext --static=$HOME/static install

会报错error: option --static must not have an argument(暂时没去尝试如何解决)

故此,找releases版本来安装

cd $HOME/src
wget https://github.com/aleaxit/gmpy/releases/download/gmpy2-2.1.0a1/gmpy2-2.1.0a1.tar.gz
tar xf gmpy2-2.1.0a1.tar.gz && cd gmpy2-2.1.0a1
python setup.py build_ext --static=$HOME/static install

安装后,命令行进入python模式后,输入import gmpy2没报错就成功了。

 

==============================

本文转自https://www.cnblogs.com/pcat/p/5746821.html

 

 

posted @ 2018-03-15 20:33  ESHLkangi  阅读(1211)  评论(0编辑  收藏  举报