linux-centos6.9下python2.6与python3.6共存
我这里是centos6.9为例
1.查看目前的python版本
[root@Adfuser-Test ~]# python -V Python 2.6.6 [root@Adfuser-Test ~]#
2.使用which python插卡python可执行文件
[root@Adfuser-Test ~]# which python /usr/bin/python [root@Adfuser-Test ~]#
3.备份一下
- cp -a /usr/bin/python /usr/bin/python.bak
4.执行软链接
- ls -l /usr/bin/python*
总结:其实直接安装rpm包即可,没有这么多依赖。
-rwxr-xr-x. 2 root root 9032 12月 24 2019 /usr/bin/python lrwxrwxrwx. 1 root root 6 12月 24 17:07 /usr/bin/python2 -> python -rwxr-xr-x. 2 root root 9032 8月 18 2019 /usr/bin/python2.6 -rwxr-xr-x. 1 root root 9032 12月 24 2019 /usr/bin/python.bak
5.查看python路径
- whreis python
[root@Adfuser-Test ~]# whereis python python: /usr/bin/python2.6 /usr/bin/python /usr/bin/python.bak /usr/lib/python2.6 /usr/lib64/python2.6 /usr/include/python2.6 /usr/share/man/man1/python.1.gz [root@Adfuser-Test ~]#
6.安装依赖
- yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
7.安装python3.6.5
#进入目录
- cd /data/software
#下载包
- wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
#解压
- tar -xvJf Python-3.6.5.tar.xz
# 进入目录
- cd Python-3.6.5
# 编译安装
./configure prefix=/usr/local/python3
报错了:
[root@Adfuser-Test Python-3.6.5]# ./configure prefix=/usr/local/python3 checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking for python3.6... no checking for python3... no checking for python... python checking for --enable-universalsdk... no checking for --with-universal-archs... no checking MACHDEP... linux checking for --without-gcc... no checking for --with-icc... no checking for gcc... no checking for cc... no checking for cl.exe... no configure: error: in `/root/data/software/Python-3.6.5': configure: error: no acceptable C compiler found in $PATH See `config.log' for more details [root@Adfuser-Test Python-3.6.5]#
尝试过很多种解决办法,百度给的最多的办法是:yum install gcc,明明gcc环境已经有了,但还是提示没有C环境呢?那一定就是yum没有安装gcc成功,于是我试试gcc命令:
如果提示命令找不到,则表明没有安装,如下:
[root@Adfuser-Test ~]# gcc -bash: gcc: command not found [root@Adfuser-Test ~]#
yum install gcc解决办法:
Oracle Linux 6
执行上面的语句之后,我再执行yum install gcc,提示如下:
[root@Adfuser-Test yum.repos.d]# yum install gcc 已加载插件:fastestmirror, refresh-packagekit, security 设置安装进程 Loading mirror speeds from cached hostfile * epel: mirrors.aliyun.com * remi-safe: repo1.dal.innoscale.net ol6_UEK_latest | 2.5 kB 00:00 ol6_latest | 2.7 kB 00:00 ol6_u6_base | 1.4 kB 00:00 ol6_u6_base/primary | 3.3 MB 00:02 ol6_u6_base 8800/8800 解决依赖关系 --> 执行事务检查 ---> Package gcc.x86_64 0:4.4.7-23.0.1.el6 will be 安装 --> 处理依赖关系 libgomp = 4.4.7-23.0.1.el6,它被软件包 gcc-4.4.7-23.0.1.el6.x86_64 需要 --> 处理依赖关系 cpp = 4.4.7-23.0.1.el6,它被软件包 gcc-4.4.7-23.0.1.el6.x86_64 需要 --> 处理依赖关系 cloog-ppl >= 0.15,它被软件包 gcc-4.4.7-23.0.1.el6.x86_64 需要 --> 处理依赖关系 libgcc >= 4.4.7-23.0.1.el6,它被软件包 gcc-4.4.7-23.0.1.el6.x86_64 需要 --> 执行事务检查 ---> Package cloog-ppl.x86_64 0:0.15.7-1.2.el6 will be 安装 --> 处理依赖关系 libppl.so.7()(64bit),它被软件包 cloog-ppl-0.15.7-1.2.el6.x86_64 需要 --> 处理依赖关系 libppl_c.so.2()(64bit),它被软件包 cloog-ppl-0.15.7-1.2.el6.x86_64 需要 ---> Package cpp.x86_64 0:4.4.7-23.0.1.el6 will be 安装 ---> Package libgcc.x86_64 0:4.4.7-18.el6 will be 升级 ---> Package libgcc.x86_64 0:4.4.7-23.0.1.el6 will be an update ---> Package libgomp.x86_64 0:4.4.7-18.el6 will be 升级 ---> Package libgomp.x86_64 0:4.4.7-23.0.1.el6 will be an update --> 执行事务检查 ---> Package ppl.x86_64 0:0.10.2-11.el6 will be 安装 --> 完成依赖关系计算 依赖关系解决 ================================================================================================================= 软件包 架构 版本 仓库 大小 ================================================================================================================= 正在安装: gcc x86_64 4.4.7-23.0.1.el6 ol6_latest 10 M 为依赖而安装: cloog-ppl x86_64 0.15.7-1.2.el6 ol6_latest 93 k cpp x86_64 4.4.7-23.0.1.el6 ol6_latest 3.7 M ppl x86_64 0.10.2-11.el6 ol6_latest 1.3 M 为依赖而更新: libgcc x86_64 4.4.7-23.0.1.el6 ol6_latest 104 k libgomp x86_64 4.4.7-23.0.1.el6 ol6_latest 135 k 事务概要 ================================================================================================================= Install 4 Package(s) Upgrade 2 Package(s) 总文件大小:16 M 确定吗?[y/N]:y 下载软件包: warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle 获取 GPG 密钥失败:[Errno 14] Could not open/read file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle [root@Adfuser-Test yum.repos.d]#
获取密钥失败,解决办法:
这是由于yum安装了旧版本的GPG key或者key文件不存在s造成的,解决办法如下:
第一种方式:
使用如下命令导入
- rpm --import /etc/pki/rpm-gpg/RPM*
成功后,再执行yum install gcc,还是提示密钥失败
第二种方式:
- 把gpgcheck=1 改为gpgcheck=0 即可,意思是在安装的时候不进行源的检查
[epel] name=Extra Packages for Enterprise Linux 6 - $basearch #baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch failovermethod=priority enabled=1 gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
成功后,再执行yum install gcc,还是提示密钥失败
第三种方式:
尝试更换yum源,试过163和阿里云
- wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
再执行yum install gcc ,提示如下
http://mirrors.aliyun.com/centos/6/addons/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found" 尝试其他镜像。 To address this issue please refer to the below knowledge base article
第四种方式:
- 修改vi /etc/yum.repos.d/CentOS-Base.repo文件内容,
$releasever直接改成6,而不是6.0,系统变量默认出来是6.0,所以错了,以及将gpgcheck=1改成0(不检查源)
再执行yum install gcc,还是提示密钥失败
解决办法:更换yum
更换阿里yum
1、下载wget
yum install -y wget
2、备份默认的yum
mv /etc/yum.repos.d /etc/yum.repos.d.backup
3、设置新的yum目录
mkdir /etc/yum.repos.d
4、下载阿里yum配置到该目录中
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
5、重建缓存
yum clean all yum makecache
6、升级所有包(改变软件设置和系统设置,系统版本内核都升级,需要几分钟耐心等待)
yum update -y
7、安装相关依赖
yum groupinstall -y Development tools
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
3、创建一个文件夹放python3
- mkdir /usr/local/python3/
4、将压缩包移到创建的python3文件夹
- mv Python-3.7.1.tar.xz /usr/local/python3
5、切换到python3文件夹下 解压下载包
- tar -xvJf Python-3.7.1.tar.xz
6、切换进入
- cd Python-3.6.5
7、编译安装
- ./configure prefix=/usr/local/python3
执行结果如下:
...
If you want a release build with all stable optimizations active (PGO, etc),
please run ./configure --enable-optimizations
- ./configure --enable-optimizations
执行结果如下:
...... checking for /dev/ptc... no checking for %zd printf() format support... yes checking for socklen_t... yes checking for broken mbstowcs... no checking for --with-computed-gotos... no value specified checking whether gcc -pthread supports computed gotos... yes checking for build directories... done checking for -O2... yes checking for glibc _FORTIFY_SOURCE/memmove bug... no checking for gcc ipa-pure-const bug... no checking for stdatomic.h... no checking for GCC >= 4.7 __atomic builtins... no checking for ensurepip... upgrade checking if the dirent structure of a d_type field... yes checking for the Linux getrandom() syscall... no checking for the getrandom() function... no checking for pkg-config... /usr/bin/pkg-config checking whether compiling and linking against OpenSSL works... yes checking for X509_VERIFY_PARAM_set1_host in libssl... no checking for --with-ssl-default-suites... python configure: creating ./config.status config.status: creating Makefile.pre config.status: creating Misc/python.pc config.status: creating Misc/python-config.sh config.status: creating Modules/ld_so_aix config.status: creating pyconfig.h config.status: pyconfig.h is unchanged creating Modules/Setup creating Modules/Setup.local creating Makefile [root@Adfuser-Test Python-3.7.1]#
成功!再执行命令:
- make && make install
执行结果如下:
...... rm -f /usr/local/bin/2to3 (cd /usr/local/bin; ln -s 2to3-3.7 2to3) rm -f /usr/local/bin/pyvenv (cd /usr/local/bin; ln -s pyvenv-3.7 pyvenv) if test "x" != "x" ; then \ rm -f /usr/local/bin/python3-32; \ (cd /usr/local/bin; ln -s python3.7-32 python3-32) \ fi rm -f /usr/local/share/man/man1/python3.1 (cd /usr/local/share/man/man1; ln -s python3.7.1 python3.1) if test "xupgrade" != "xno" ; then \ case upgrade in \ upgrade) ensurepip="--upgrade" ;; \ install|*) ensurepip="" ;; \ esac; \ ./python -E -m ensurepip \ $ensurepip --root=/ ; \ fi Looking in links: /tmp/tmpys7u980z Collecting setuptools Collecting pip Installing collected packages: setuptools, pip Successfully installed pip-10.0.1 setuptools-39.0.1
验证python版本


浙公网安备 33010602011771号