1.通过按pip install virtualenv
2.安装pyenv(推荐)
安装相关环境包:
#yum groupinstall "Development tools"
#yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel #readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
安装 pyenv
#curl https://raw.github.com/yyuu/pyenv-installer/master/bin/pyenv-installer |bash
或者
git clone git://github.com/yyuu/pyenv.git .pyenv #.pyenv 为虚拟目录
3.创建环境变量:
[[email protected] ~]# cat /etc/profile.d/pyenv.sh #!/bin/bash ################# export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init -)" [[email protected] ~]#source /etc/profile.d/pyenv.sh [[email protected] ~]# cat ~/.pip/pip.conf #设置pip国内源(可选); [global] index-url = http://pypi.douban.com/ [[email protected] ~]#
4.测试
[[email protected] ~]# pyenv install --list #显示可安装的包 [[email protected] ~]# pyenv install 3.4.3 #安装python3.4.3 [[email protected] ~]# pyenv local system #本地切换系统默认的python版本 [[email protected] ~]# python -V #查看系统当前的版本 Python 2.7.5 [[email protected] ~]# pyenv local 3.4.3 #本地切换python3.4.3版本 [[email protected] ~]# pyenv shell 3.4.3 #和上类似 [[email protected] ~]# python -V Python 3.4.3 [[email protected] ~]#pyenv global system [[email protected] ~]# pyenv versions #查看系统当前可用的python版本,以及正在使用的版本 system * 3.4.3 (set by /root/.python-version)
时间: 2024-10-10 04:52:00