在CentOS6里面,python默认的版本是2.6,最多也就到2.6.6如果采用yum update的方式,但是有些程序我们必须使用高版本的python,怎么办呢?

用virtualenv,python的虚拟环境。

  • 编译之前,要安装zlib-devel,打出libz.so,否则,virtualenv的时候会报import zlib error。
yum install zlib zlib-devel openssl-devel
  • 下载并编译安装python2.7
cd /usr/local/src/
#wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz
#tar xzvf Python-2.7.12.tgz
wget http://static.opschina.org/uploads/20170218132247.tgz
tar xzvf 20170218132247.tgz
cd Python-2.7.12
./configure --prefix=/usr/local/python-2.7.12 --with-ssl
make -j 4
make install

python虚拟环境

pip install virtualenv
  • 打出python2.7的虚拟环境,目标目录/usr/local/myenv
virtualenv -p /usr/local/python-2.7.12/bin/python2.7 /usr/local/myenv
  • 进入虚拟环境
source /usr/local/myenv/bin/activate
  • 退出虚拟环境
deactivate
Copyright © opschina.org 2017 with zzlyzq@gmail.com all right reserved,powered by Gitbook该文件修订时间: 2017-07-11 11:32:48

results matching ""

    No results matching ""