gmpy2安装使用方法
GMP(GNU Multiple Precision Arithmetic Library,即GNU高精度算术运算库),它是一个开源的高精度运算库,其中不但有普通的整数、实数、浮点数的高精度运算,还有随机数生成,尤其是提供了非常完备的数论中的运算接口,比如Miller-Rabin素数测试算法、大素数生成、欧几里德算法、求域中元素的逆、Jacobi符号、legendre符号等。
gmpy2是Python的一个扩展库,是对GMP的封装,它的前身是gmpy,经过其作者的调整和封装,使得gmpy2的使用大大简化。
官方文档:https://gmpy2.readthedocs.io/en/latest/
-------
1、windows上安装gmpy2
在windows上直接安装wheel文件就方便多了。
https://pypi.org/project/gmpy2/#files
这里面有python2.6、2.7、3.2、3.3、3.4版本的wheel文件,下载后用pip安装即可。(暂时还找不到3.5版本)
后来也发现有一个gmpy2-2.0.8.win-amd64-py2.7.exe文件。
-= 2018.01补充 =-
现在gmpy2 2.1.0a1里可以支持3.4+
2、linux上安装gmpy2
gmpy2是依赖GMP、MPFR、MPC三个库,故此在linux上安装前得先安装这3个库。
为了后续安装的方便,先建立2个文件夹。
mkdir -p $HOME/src
mkdir -p $HOME/static
-= 2018.04补充 =-
测试有没有安装m4模块:
man m4
如果出现No manual entry for m4,就说明没有安装m4模块。
如果没安装m4模块,在编译GMP时候会报错checking for suitable m4... configure: error: No usable m4 in $PATH or /usr/5bin (see config.log for reasons).
安装m4:
GNU M4 is an implementation of the traditional Unix macro processor. It is mostly SVR4 compatible although it has some extensions (for example, handling more than 9 positional parameters to macros). GNU M4 also has built-in functions for including files, running shell commands, doing arithmetic, etc.
当前最新的是1.4.18
v=1.4.
cd $HOME/src
wget http://ftp.gnu.org/gnu/m4/m4-${v}.tar.gz
tar xf m4-${v}.tar.gz && cd m4-${v}
./configure -prefix=/usr/local
make && make check && make install
3、安装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
v=6.1.
cd $HOME/src
wget https://gmplib.org/download/gmp/gmp-${v}.tar.bz2
tar -jxvf gmp-${v}.tar.bz2 && cd gmp-${v}
./configure --prefix=$HOME/static --enable-static --disable-shared --with-pic
make && make check && make install
4、安装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 (请自己访问官网,替换成最新的版本号)
v=4.0.
cd $HOME/src
wget http://www.mpfr.org/mpfr-current/mpfr-${v}.tar.bz2
tar -jxvf mpfr-${v}.tar.bz2 && cd mpfr-${v}
./configure --prefix=$HOME/static --enable-static --disable-shared --with-pic --with-gmp=$HOME/static
make && make check && make install
-= 2018.04补充 =-
如果mpfr.org下载太慢,可以换为
wget http://ftp.gnu.org/gnu/mpfr/mpfr-${v}.tar.bz2
5、安装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版本
v=1.1.
cd $HOME/src
wget ftp://ftp.gnu.org/gnu/mpc/mpc-${v}.tar.gz
tar -zxvf mpc-${v}.tar.gz && cd mpc-${v}
./configure --prefix=$HOME/static --enable-static --disable-shared --with-pic --with-gmp=$HOME/static --with-mpfr=$HOME/static
make && make check && make install
6、安装gmpy2
github项目:https://github.com/aleaxit/gmpy
现在新的版本(2-2.1.0b1以上版本)在执行python setup.py build_ext --static=$HOME/static install
会报错error: option --static must not have an argument
解决法子1:
找releases版本(2-2.1.0a1以下版本)来安装
v=-2.1.0a1
cd $HOME/src
wget https://github.com/aleaxit/gmpy/releases/download/gmpy${v}/gmpy${v}.tar.gz
tar xf gmpy${v}.tar.gz && cd gmpy${v}
python setup.py build_ext --static=$HOME/static install
解决法子2:
因为新版本的setup.py修改了不少,故得采用以下法子:
python setup.py build_ext --static-dir=$HOME/static install
安装后,命令行进入python模式后,输入import gmpy2没报错就成功了。
-= 2018.04补充 =-
如果使用wget下载时候一直卡在:
Connecting to github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)|52.216.227.24|:443...
可以尝试:
echo 52.216.16.16 github-production-release-asset-2e65be.s3.amazonaws.com >>/etc/hosts
/etc/init.d/networking restart
-= 2018.05补充 =-
如果报错fatal error: Python.h: 没有那个文件或目录
apt-get install python-dev
7、gmpy2使用方法
这里pcat就介绍找一百以内的素数,更多gmpy2的用法自己搜索吧,或者以后补充(←_←)。
import gmpy2
for i in xrange(100+1):
if gmpy2.is_prime(i):
print i
gmpy2安装使用方法的更多相关文章
- 安装Birt方法
安装BIRT 方法: 博客地址:http://www.mamicode.com/info-detail-850588.html 注意:在 Install new Software 中输入地址:http ...
- linux php安装扩展方法 查找配置文件
如何在linux中查看nginx.apache.php.mysql配置文件路径了,如果你接收一个别人配置过的环境,但没留下相关文档.这时该怎么判断找到正确的加载文件路径了.可以通过以下来判断 1.判断 ...
- node安装插件方法
node安装插件方法有几种,这里列出常用的两种方法: 方法1: 进入要安装插件的目录,直接用 npm 软件安装包安装,如(安装express): cd /project npm install -g ...
- windows server 2008见安装IIS方法(解决)
windows server 2008见安装IIS方法(解决) 刚开始有点蒙,后来才知道原来如此.! . 右键点击[我的电脑]--[管理]--[字符]--[加入角色]--仅落后win7像.啊! 版权声 ...
- elasticsearch+kibana+metricbeat安装部署方法
elasticsearch+kibana+metricbeat安装部署方法 本文是elasticsearch + kibana + metricbeat,没有涉及到logstash部分.通过beat收 ...
- RHEL6下获取安装包(RPM)而不安装的方法
RHEL6下获取安装包(RPM)而不安装的方法 有时候我们只能在某个机器上网获得RPM安装包,如何将RPM包在不能上网的内网机器安装,就需要能将安装包下载到本地而不安装,然后再把这些包复制到内网机器, ...
- 哈希长度扩展攻击(Hash Length Extension Attack)利用工具hexpand安装使用方法
去年我写了一篇哈希长度扩展攻击的简介以及HashPump安装使用方法,本来已经足够了,但HashPump还不是很完善的哈希长度扩展攻击,HashPump在使用的时候必须提供original_data, ...
- windows Sever 2012下Oracle 12c安装配置方法图文教程
windows Sever 2012下Oracle 12c安装配置方法图文教程 Oracle 12c安装配置方法图文教程,具体内容如下 1.我们开启虚拟机 2.Windows Sever 2012启动 ...
- 安装rcssmin方法
#安装rcssmin方法'''pip install wheelpip install rcssmin --install-option="--without-c-extensions&qu ...
随机推荐
- Ubuntu Code::Blocks IDE 13.12 汉化
Ubuntu Code::Blocks IDE 13.12 汉化: 安装很简单,不再赘述. 单说汉化: .下载中文简体汉化包(百度网盘):链接: http://pan.baidu.com/s/1kU3 ...
- HTML界面JQuery ajax 返回200,但走Error方法
原因是JSON拼装的有问题. 都需要放在双引号里面,或者修改dataType的类型为 "html". http://blog.csdn.net/imjcoder/article/ ...
- 经典:十步完全理解 SQL
经典:十步完全理解 SQL 来源:伯乐在线 链接:http://blog.jobbole.com/55086/ 很多程序员视 SQL 为洪水猛兽.SQL 是一种为数不多的声明性语言,它的运行方式完 ...
- QF——OC中的SEL类型和Block
@selector(): 可以理解@selector()就是取类方法的编号,他的基本行为类似于C语言中的函数指针(指向函数的指针).它们通过传递方法的地址(或编号)来实现把方法当做参数的效果. 不过在 ...
- python打包成.exe工具py2exe0-----No such file or directory错误
转自:http://justcoding.iteye.com/blog/900993 一.简介 py2exe是一个将python脚本转换成windows上的可独立执行的可执行程序(*.exe)的工具, ...
- jQuery滚动广告 解决子div绝对定位与父div重叠引起的闪烁问题
这两天做了一个滚动广告栏的demo 功能有自动轮播 左右箭头移动 导航点选中图片移动效果 模仿的是新浪体育的广告 最难的问题就是子div绝对定位于父div 鼠标移入子div 系统会判定鼠标移出了父di ...
- Ajax应用常见的HTTP ContentType设置
文章出处:Ajax应用常见的HTTP ContentType设置 ajax开发中, 常遇到下面的几种情况: 1 服务端需要返回一段普通文本给客户端 2 服务端需要返回一段HTML代码给客户端 3 服务 ...
- [Python]豆瓣用户读书短评下载工具
简介 朋友问我能不能做一个下载他在豆瓣读书上的短评的工具,于是就做了这个“豆瓣用户读书短评下载工具”. GitHub链接:https://github.com/xiaff/dbc-downloader ...
- 【Chromium中文文档】Chrom{e,ium}{,OS}中的硬件视频加速
Chrom{e,ium}{,OS}中的硬件视频加速 转载请注明出处:https://ahangchen.gitbooks.io/chromium_doc_zh/content/zh//General_ ...
- Linux中的网络
在windows 中表示一张网卡用本地连接1,本地连接2这种方式来表示:而在linux 中用的是etho,eth1 等等这样的东西来表示的.