python3.6安装

虽然草鸡简单,不过本着知识的连贯性,发下吧,万一某天给小朋友看呢,毕竟现在中小学都玩python了,也多给搜索引擎贡献点资源

首先装几个编译时候用的,大部分的设备应该装了,yum一下吧防止没装

yum -y install openssl-devel readline-devel unzip

下载3.6版本的python

wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz

或者直接去python的官网下
https://www.python.org/

python3.6安装_第1张图片
image.png

下载完成就可以按照喽

tar xvf Python-3.6.4.tgz
cd Python-3.6.4/
./configure --prefix=/usr/local/python36
make && make install

安装完成后可以直接到/usr/local/python36下进行使用

比如通过python36的pip安装virtualenv

/usr/local/python36/bin/pip3 install virtualenv
#安装完成后就可以通过virtualenv创建虚拟环境喽
/usr/local/python36/bin/virtualenv ./python36env

如果要把系统中原始的2.x版本的python干掉的话,额 其实不建议 很多系统基本的python程序其实是有依赖的,比如yum的程序。

那么如果要2,3版本共存怎么办?

[root@xxx01 ~]# cd /usr/local/python36/bin
[root@xxx01 bin]# ll
total 24772
lrwxrwxrwx 1 root root        8 May 20 12:49 2to3 -> 2to3-3.6
-rwxr-xr-x 1 root root      110 May 20 12:49 2to3-3.6
-rwxr-xr-x 1 root root      251 May 20 12:49 easy_install-3.6
lrwxrwxrwx 1 root root        7 May 20 12:49 idle3 -> idle3.6
-rwxr-xr-x 1 root root      108 May 20 12:49 idle3.6
-rwxr-xr-x 1 root root      223 May 20 12:49 pip3
-rwxr-xr-x 1 root root      223 May 20 12:49 pip3.6
lrwxrwxrwx 1 root root        8 May 20 12:49 pydoc3 -> pydoc3.6
-rwxr-xr-x 1 root root       93 May 20 12:49 pydoc3.6
lrwxrwxrwx 1 root root        9 May 20 12:49 python3 -> python3.6
-rwxr-xr-x 2 root root 12661917 May 20 12:48 python3.6
lrwxrwxrwx 1 root root       17 May 20 12:49 python3.6-config -> python3.6m-config
-rwxr-xr-x 2 root root 12661917 May 20 12:48 python3.6m
-rwxr-xr-x 1 root root     3126 May 20 12:49 python3.6m-config
lrwxrwxrwx 1 root root       16 May 20 12:49 python3-config -> python3.6-config
lrwxrwxrwx 1 root root       10 May 20 12:49 pyvenv -> pyvenv-3.6
-rwxr-xr-x 1 root root      450 May 20 12:49 pyvenv-3.6
-rwxr-xr-x 1 root root      230 May 20 12:50 virtualenv

我们看到程序本身是有带python3.6的标识的,那么我们再看下系统本身的python

[root@xxx01 bin]# which python
/bin/python
[root@xxx01 bin]# ll /bin/python
lrwxrwxrwx 1 root root 7 Jun  8  2017 /bin/python -> python2
[root@xxx01 bin]# ll /bin/python2
lrwxrwxrwx 1 root root 9 Jun  8  2017 /bin/python2 -> python2.7
[root@xxx01 bin]# ll /bin/python2.7
-rwxr-xr-x 1 root root 7136 Nov 20  2015 /bin/python2.7
[root@xxx01 bin]#

我们看到了python默认是指向了软链的python2.7那么其实我们可以不动他们互相不影响,直接将python3.6环境中需要用的包软链到/bin/下即可,比如下面这样操作

[root@xxx01 ~]# ln -s /usr/local/python36/bin/python3 /bin/python3
[root@xxx01 ~]# ln -s /usr/local/python36/bin/pip3 /bin/pip3
[root@xxx01 ~]# which  python3
/bin/python3
[root@xxx01 ~]# python3 -V
Python 3.6.4

操作完成后,本机的需要使用python3环境的程序 指定为python3的版本即可,默认环境仍然是python2版本

make install , 报错: 
[zipimport.ZipImportError: can't decompress data; zlib not available](http://www.cnblogs.com/MnCu8261/articles/5835604.html)
cd Modules/zlib  
./configure  
make install  
cd -  
make altinstall  

你可能感兴趣的:(python3.6安装)