centos7安装python3.6.5

2023-01-31 02:01:10 centos7 安装 6.5

安装python3.6可能使用相关软件


# yum groupinstall 'Development Tools'
# yum install -y ncurses-libs zlib-devel Mysql-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

安装python3.6.5

python官网下载https://www.python.org

下载的安装包存放在/usr/local目录

# cd /usr/local

# wget https://www.python.org/ftp/Python/3.6.5/Python-3.6.5.tar.xz

解压:

# tar -xf Python-3.6.5.tar.xz

解压后新建文件夹将Python-3.6.5放在/usr/local/python3下

进入该目录····························一定要进去的哈,不然安装会出错

# mkdir python3
# mv Python-3.6.5 python3
# cd python3/Python-3.6.5

执行如下代码安装

···························--prefix选项是配置安装的路径,执行后所有资源文件放在/usr/local/python3.6的路径中

# ./configure --prefix=/usr/local/python3 --enable-optimizations
# make
# make altinstall

修改软链接:

修改之前一定要对以存在的/usr/bin/python更名,否则出现如下错误

ln: failed to create symbolic link ‘/usr/bin/python’: File exists

可修改为:

# mv python python_old

························当然任意名字都可

终于可以修改软链接了

# ln -s /usr/local/python3/bin/python3 /usr/bin/python
# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip

最后修改yum/gnome-tweak-tool/urlgrabber配置文件,否则之后使用yum可能报错

[root@VM_0_8_Centos bin]# ls -ol yum*
-rwxr-xr-x  1 root   802 May 24 23:05 yum
-rwxr-xr-x  1 root  9430 May 24 23:06 yum-builddep
-rwxr-xr-x  1 root  9040 May 24 23:05 yum-config-manager
-rwxr-xr-x  1 root  7610 May 24 23:06 yum-debug-dump
-rwxr-xr-x  1 root  7904 May 24 23:07 yum-debug-restore
-rwxr-xr-x. 1 root 10999 Aug 11  2017 yumdownloader
-rwxr-xr-x  1 root 11032 May 24 23:07 yum-groups-manager

以上文件都要修改文件行首处 #!/usr/bin/python

改为 #!/usr/bin/python2

输入:

# vim yum-builddep

[root@VM_0_8_centos bin]# vim yum-builddep

#!/usr/bin/python -tt        !!!!!!!!!!!!!!!!!!就是改这里 加个2 ·················哈哈

# This program is free software; you can Redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
····························省略一万字


gnome-tweak-tool/urlgrabber配置文件修改同上 ·········gnome-tweak-tool可能无须配置

最后查看安装版本:

# python -V
# pip -V




相关文章