Centos7下不删除python2.x的情况下安装python3.x

时间:2023-03-10 07:21:36
Centos7下不删除python2.x的情况下安装python3.x

Linux下默认系统自带python2.X的版本,这个版本被系统很多程序所依赖,所以不建议删除,如果使用最新的Python3那么我们知道编译安装源码包和系统默认包之间是没有任何影响的,所以可以安装python3和python2共存

1、下载linux平台的python3.x的安装包(我下载的是python3.6版本)

[root@localhost ~]# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz

2、解压python3.6安装包

[root@localhost ~]# tar xf Python-3.6..tgz
[root@localhost ~]# ll
total
-rw-------. root root Jun : anaconda-ks.cfg
drwxr-xr-x. Mar : Python-3.6.
-rw-r--r--. root root Mar : Python-3.6..tgz

3、安装python3.6,默认安装路径为/usr/local

  --prefix=PREFIX install architecture-independent files in PREFIX
  [/usr/local]

#安装报错,缺失依赖库
[root@localhost Python-3.6.]# ./configure
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for python3.... 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/Python-3.6.':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
#安装依赖库
[root@localhost Python-3.6.]# yum install gcc #安装python3.
[root@localhost Python-3.6.]# make && make install #make && make install 报错
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error
#安装zlib-devel
[root@localhost Python-3.6.]# yum install zlib-devel
#重新安装
[root@localhost Python-3.6.]# make && make install

4、python3.6已安装成功,在/usr/local/bin下生成命令python3

[root@localhost local]# ll /usr/local/bin/
total
lrwxrwxrwx. root root Jun : 2to3 -> 2to3-3.6
-rwxr-xr-x. root root Jun : 2to3-3.6
-rwxr-xr-x. root root Jun : easy_install-3.6
lrwxrwxrwx. root root Jun : idle3 -> idle3.
-rwxr-xr-x. root root Jun : idle3.
-rwxr-xr-x. root root Jun : pip3
-rwxr-xr-x. root root Jun : pip3.
lrwxrwxrwx. root root Jun : pydoc3 -> pydoc3.
-rwxr-xr-x. root root Jun : pydoc3.
lrwxrwxrwx. root root Jun : python3 -> python3.
-rwxr-xr-x. root root Jun : python3.
lrwxrwxrwx. root root Jun : python3.-config -> python3.6m-config
-rwxr-xr-x. root root Jun : python3.6m
-rwxr-xr-x. root root Jun : python3.6m-config
lrwxrwxrwx. root root Jun : python3-config -> python3.-config
lrwxrwxrwx. root root Jun : pyvenv -> pyvenv-3.6
-rwxr-xr-x. root root Jun : pyvenv-3.6

5、使用python3命令查看版本

[root@localhost local]# python3 -V
Python 3.6.
[root@localhost local]# python3
Python 3.6. (default, Jun , ::)
[GCC 4.8. (Red Hat 4.8.-)] on linux
Type "help", "copyright", "credits" or "license" for more information.

参考:http://www.cnblogs.com/freeweb/p/5181764.html