1.python位置
[root@iZm5e0imc5aczk2ej2pq1oZ ~]# whereis python
python: /usr/bin/python /usr/bin/python2.7 /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /usr/share/man/man1/python.1.gz
2.python在 /usr/bin目录中, 查看吧python指向
[root@root ~]# cd /usr/bin/
[root@root bin]# ll python*
lrwxrwxrwx. 1 root root 7 2月 7 09:30 python -> python2
lrwxrwxrwx. 1 root root 9 2月 7 09:30 python2 -> python2.7
-rwxr-xr-x. 1 root root 7136 8月 4 2017 python2.7
3.因为我们要安装python3,所以要先安装相关包,用于下载编译python
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
4.下载python3
wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz
5.编译
#解压
xz -d Python-3.6.4.tar.xz
tar -xf Python-3.6.4.tar
#进入解压后的目录,依次执行下面命令进行手动编译
./configure prefix=/usr/local/python3
make && make install
6.为python添加软连接
#将原来的链接备份
mv /usr/bin/python /usr/bin/python.bak
#添加python3的软链接
ln -s /usr/local/python3/bin/python3.6 /usr/bin/python
#添加pip3软连接
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
#测试是否安装成功了
python -V
pip -V
7.更改yum配置,因为其要用到python2才能执行,否则会导致yum不能正常使用
vi /usr/bin/yum
把#! /usr/bin/python修改为#! /usr/bin/python2
vi /usr/libexec/urlgrabber-ext-down
把#! /usr/bin/python 修改为#! /usr/bin/python2
安装虚拟环境
1.安装virtualenv
pip install virtualenv
2.安装virtualenvwrapper
pip install virtualenvwrapper
3.找到virtualenvwrapper.sh
find / -name virtualenvwrapper.sh
如果不在/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin里
将virtualenvwrapper.sh复制到/usr/local/bin/virtualenvwrapper.sh
4.找到virtualenv
find / -name virtualenvwrapper.sh
如果不在/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin里
将virtualenvwrapper.sh复制到/usr/local/bin/virtualenv
5.mkvirtualenv 虚拟环境名字就可以用了
workon也可以用了