安装python2.7
CentOS7上默认安装的是python2.7.5,在服务器上
首先安装epel扩展源:
yum -y install epel-release
然后安装python-pip
yum -y install python-pip
[root@localhost ~]# python --version
Python 2.7.5
[root@localhost ~]# pip --version
pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)
安装完之后别忘了清除一下cache
yum clean all
安装python3
在官方网站下载
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz
tar -zxvf Python-3.6.2.tgz
cd Python-3.6.2/
./configure --prefix=/usr/local
make
make install
Successfully installed pip-9.0.1 setuptools-28.8.0
[root@localhost Python-3.6.2]# python --version
Python 2.7.5
[root@localhost Python-3.6.2]# python3 --version
Python 3.6.2
[root@localhost Python-3.6.2]# pip --version
pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)
[root@localhost Python-3.6.2]# pip3 --version
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
在写Python代码的时候,文件头部都加上:
#!/usr/bin/env python3
# coding=utf-8