python 3.6.5编译安装_Centos7下编译安装python3.6.5

一、下载源码包并编译安装[root@iZtmm4mufhb0rgZ /]# wget  https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz

[root@iZtmm4mufhb0rgZ /]# tar xzvf Python-3.6.5.tgz

[root@iZtmm4mufhb0rgZ /]# cd Python-3.6.5

[root@iZtmm4mufhb0rgZ /]#  ./configure --enable-shared --prefix=/usr/local CFLAGS=-fPIC LDFLAGS="-Wl,-rpath /usr/local/lib" --with-ssl

[root@iZtmm4mufhb0rgZ Python-3.6.5]# make -j24 && make install

-------------------------安装成功---------------------------------

Collecting pip

Installing collected packages: setuptools, pip

Successfully installed pip-9.0.3 setuptools-39.0.1

二、添加程序的软连接

自3.4版本起,setup_tools及pip工具自动安装,所以不用再手动安装了[root@iZtmm4mufhb0rgZ Python-3.6.5]# sudo ln -sf /usr/local/bin/python3.6 /usr/bin/python3

[root@iZtmm4mufhb0rgZ Python-3.6.5]# sudo ln -sf /usr/local/bin/python3.6 /usr/bin/python3.6

[root@iZtmm4mufhb0rgZ Python-3.6.5]# sudo  ln -sf /usr/local/bin/pip3.6 /usr/bin/pip3

[root@iZtmm4mufhb0rgZ Python-3.6.5]# sudo  ln -sf /usr/local/bin/pip3.6 /usr/bin/pip3.6

遇到的错误以及解决方法:

第一个坑:编译安装时报以下错误zipimport.ZipImportError: can't decompress data; zlib not available

make: *** [install] Error 1

-------------------------------------------------------------------

[root@iZtmm4mufhb0rgZ Python-3.6.5]# yum install -y zlib*        ##解决办法;安装zlib软件包重新编译即可

第二个坑:执行命令报错

这两类是一个错误,因为库不在pyhon3这个程序可以正确连接的地方[root@iZtmm4mufhb0rgZ Python-3.6.5]# sudo python3

python3: error while loading shared libraries: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory

[root@iZtmm4mufhb0rgZ Python-3.6.5]# sudo pip3 install numpy

/usr/local/bin/python3.6: error while loading shared libraries: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory

有两种解决方案,一种是在./configure加入LDFLAGS="-Wl,-rpath /usr/local/lib" 手动指定,另一种是设定全局变量LD_LIBRARY_PATH。显然第一种方案更好一些,第二种方案导致普通用户程序感染root程序的执行,危害很大。

第三个坑:使用pip安装模块时提示找不到ssl模块

原因是:在./configure过程中,如果没有加上–with-ssl参数时,默认安装的软件涉及到ssl的功能不可用,刚好pip3过程需要ssl模块,而由于没有指定,所以该功能不可用。pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

Could not fetch URL https:*******: There was a problem confirming the ssl certificate:

Can't connect to HTTPS URL because the SSL module is not available. - skipping

------------------------------------------------------------------------

##解决办法;./configure时加上--with-ssl选项

##解决办法2:缺少依赖包 yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值