Centos7安装Python3

发表日期:2018年1月8日 02:37

安装Python3

安装编译器、依赖包

yum install gcc-c++

yum install wget openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel mysql-devel

yum install libxml*

下载安装Python3

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

cd  /tmp/Python-3.6.4/
./configure --prefix=/usr/python3.6.4
make -j2
make install -j2

ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

Centos7默认使用Python3.6

cd /usr/bin/
mv python python.bak
ln -s /usr/python3.6.4/bin/python3.6 /usr/bin/python

为防止因为安装新版Python导致yum出错

vim /usr/bin/yum

#!/usr/bin/python  
import sys  
try:  
    import yum  

#!/usr/bin/python2.7 
import sys  
try:  
    import yum  

安装pip3

cd /usr/bin
yum -y install epel-release
ln -s /usr/python3.6.4/bin/pip3.6 /usr/bin/pip3
yum install openssl-devel -y 

安装virtualenv、virtualenvwrapper

pip install virtualenv
pip install virtualenvwrapper

修改~/.bashrc

export WORKON_HOME=$HOME/.virtualenvs
source /usr/python3.6.4/bin/virtualenvwrapper.sh


source ~./bashrc