redhat 安装python3

1、首先,官网下载python3的所需版本。

wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgzpython

想下载到那个文件夹下就先进入到那个文件夹下——cd /home/downloadlinux

2、而后,解压缩文件》

tar -xvf Python-3.6.0.tgzvim

3、建立安装文件的路径。

mkdir /usr/local/python3centos

4、编译。

进入到解压目录下缓存

./configure --prefix=/usr/local/python3ruby

5、安装。

一、makebash

二、make installsocket

 make install 报错:zipimport.ZipImportError: can’t decompress data测试

a、打开终端,输入一下命令安装zlib相关依赖包:ui

yum -y install zlib*
  
  redhat 配置yum源:
  

    进入到 /etc/yum.repos.d, 其中有个rhel-source.repo, 先更名为rhel-source.repo.bak,作个备份

    而后新建个 rhel-source.repo

    

[updates]
name=CentOS-6 - Updates - 163.com
baseurl=http://mirrors.163.com/centos/6/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
 
#additional packages that may be useful
[extras]
name=CentOS-6 - Extras - 163.com
baseurl=http://mirrors.163.com/centos/6/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

  

 
     清理并重建缓存
    yum clean all
    yum makecache
 
    更新yum
    yum update

  

b、进入 python安装包,修改Module路径的setup文件:

vim Module/Setup 

找到一下一行代码,去掉注释:

#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz 去掉注释 zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz

从新安装

 

三、完毕

6、建立新版本的软链接。

一、修改旧版本

mv /usr/bin/python /usr/bin/python_bak

二、建立新的软链接

ln -s /usr/local/python3/bin/python3 /usr/bin/python

三、检查python的版本

python -V

python-3.6.0

软链接建立成功

7、配置成功后,pip3用不了,需进一步配置。

一、export PATH=$PATH:$HOME/bin:

二、export PATH=$PATH:$HOME/bin:/usr/local/python3/bin

三、完成

这时pip3就可使用了。

 

注:升级完成后,yum没法使用,需更改yum指向源2.7版本

  vim /usr/bin/yum,第一句更改成原版本路径便可

 

后续问题

pip3安装包时报错,pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

解决方案:

>>> import ssl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/python3/lib/python3.6/ssl.py", line 60, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: No module named _ssl
>>>

2. 查看openssl安装包,发现缺乏openssl-devel包
[root@localhost ~]# rpm -aq|grep openssl
openssl-1.0.1e-57.el6.x86_64

3. yum安装openssl-devel
[root@localhost ~]# yum install openssl-devel -y


#查看安装结果
[root@localhost ~]# rpm -aq|grep openssl

openssl-1.0.1e-57.el6.x86_64
openssl-devel-1.0.1e-57.el6.x86_64

4. 从新编译python
#修改Setup文件
vi /usr/software/Python-2.7.5/Modules/Setup
#修改结果以下:
# Socket module helper for socket(2)
_socket socketmodule.c timemodule.c

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto


5. 从新编译
make
make install

6. 测试,已可正常使用。[root@localhost ~]# pythonPython 3.6.0 (default, Jan 25 2018, 22:31:55) [GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import ssl>>>

相关文章
相关标签/搜索