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

来源:互联网 发布:人力资源办公软件 编辑:程序博客网 时间:2024/05/16 15:33

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.1.tgz [root@localhost ~]# lltotal 22024-rw-------.  1 root root     1238 Jun 25 10:54 anaconda-ks.cfgdrwxr-xr-x. 17  501  501     4096 Mar 21 03:47 Python-3.6.1-rw-r--r--.  1 root root 22540566 Mar 21 03:47 Python-3.6.1.tgz

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

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

复制代码
#安装报错,缺失依赖库[root@localhost Python-3.6.1]# ./configure checking build system type... x86_64-unknown-linux-gnuchecking host system type... x86_64-unknown-linux-gnuchecking for python3.6... nochecking for python3... nochecking for python... pythonchecking for --enable-universalsdk... nochecking for --with-universal-archs... nochecking MACHDEP... linuxchecking for --without-gcc... nochecking for --with-icc... nochecking for gcc... nochecking for cc... nochecking for cl.exe... noconfigure: error: in `/root/Python-3.6.1':configure: error: no acceptable C compiler found in $PATHSee `config.log' for more details#安装依赖库[root@localhost Python-3.6.1]# yum install gcc#安装python3.6[root@localhost Python-3.6.1]# make && make install#make && make install 报错zipimport.ZipImportError: can't decompress data; zlib not availablemake: *** [install] Error 1#安装zlib-devel[root@localhost Python-3.6.1]# yum install zlib-devel#重新安装[root@localhost Python-3.6.1]# make && make install
复制代码

 

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

复制代码
[root@localhost local]# ll /usr/local/bin/total 24656lrwxrwxrwx. 1 root root        8 Jun 25 11:22 2to3 -> 2to3-3.6-rwxr-xr-x. 1 root root      101 Jun 25 11:22 2to3-3.6-rwxr-xr-x. 1 root root      242 Jun 25 11:22 easy_install-3.6lrwxrwxrwx. 1 root root        7 Jun 25 11:22 idle3 -> idle3.6-rwxr-xr-x. 1 root root       99 Jun 25 11:22 idle3.6-rwxr-xr-x. 1 root root      214 Jun 25 11:22 pip3-rwxr-xr-x. 1 root root      214 Jun 25 11:22 pip3.6lrwxrwxrwx. 1 root root        8 Jun 25 11:22 pydoc3 -> pydoc3.6-rwxr-xr-x. 1 root root       84 Jun 25 11:22 pydoc3.6lrwxrwxrwx. 1 root root        9 Jun 25 11:22 python3 -> python3.6-rwxr-xr-x. 2 root root 12604536 Jun 25 11:21 python3.6lrwxrwxrwx. 1 root root       17 Jun 25 11:22 python3.6-config -> python3.6m-config-rwxr-xr-x. 2 root root 12604536 Jun 25 11:21 python3.6m-rwxr-xr-x. 1 root root     3097 Jun 25 11:22 python3.6m-configlrwxrwxrwx. 1 root root       16 Jun 25 11:22 python3-config -> python3.6-configlrwxrwxrwx. 1 root root       10 Jun 25 11:22 pyvenv -> pyvenv-3.6-rwxr-xr-x. 1 root root      441 Jun 25 11:22 pyvenv-3.6
复制代码

5、使用python3命令查看版本

[root@localhost local]# python3 -VPython 3.6.1    [root@localhost local]# python3Python 3.6.1 (default, Jun 25 2017, 11:20:12) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linuxType "help", "copyright", "credits" or "license" for more information.

 安装时报如下错误:

zipimport.ZipImportError: can't decompress data; zlib not available

解决方法:

1、安装依赖zlib、zlib-devel

2、重新编译安装Python


  1. ./configure 
  2. 编辑Modules/Setup文件 
  3. 找到下面这句,去掉注释 
  4. #zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz 
  5. 重新编译安装:make & make install

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

原创粉丝点击