#不知道为什么我打的空格都成了换行
1、安装依赖:yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
2、git安装,需提前安装git
cd /root #切换到/root
git clone git://github.com/yyuu/pyenv.git .pyenv
3、配置环境变量:
touch/etc/profile.d/pyenv.sh
vim /etc/profile.d/pyenv.sh
添加内容:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
source/etc/profile.d/pyenv.sh
4、安装配置完成
参考:http://www.it165.net/os/html/201405/8348.html
https://github.com/yyuu/pyenv/issues/228
5、pyenv使用:
常用指令:
Usage: pyenv
Some useful pyenv commands are:
commands List all available pyenv commands
local Set or show the local application-specific Python version
global Set or show the global Python version
shell Set or show the shell-specific Python version
install Install a Python version using python-build
uninstall Uninstall a specific Python version
rehash Rehash pyenv shims (run this after installing executables)
version Show the current Python version and its origin
versions List all Python versions available to pyenv
which Display the full path to an executable
whence List all Python versions that contain the given executable
See `pyenv help
For full documentation, see: https://github.com/yyuu/pyenv#readme
常用指令使用指南:
(1)安装不同版本的Python:
首先,可以使用pyenv install -l,查看支持安装的版本,类似于yum search all,得到(这里我只列举一部分):
Available versions:
2.4.4
2.4.5
2.4.6
2.5
2.5.1
2.5.2
2.6.9
2.7.7
2.7.8
2.7.9
3.4.0
pypy-5.1.1
pypy3-dev
stackless-dev
stackless-3.4.1
找到你想要安装的版本,比如2.7.7或者pypy-5.1.1,然后安装:pyenv install 2.7.7 ; pyenv install pypy-5.1.1
(2)查看当前设为默认使用的Python版本:pyenv version
(3)查看所有Python版本:pyenv versions
system
* 2.7 (set by /root/.pyenv/version)
3.4.1
3.5.0
结果表示,正在使用2.7作为默认值,system指的是系统自带Python
(4)卸载,用上述指令找到对应版本后pyenv uninstall即可
(5)版本切换:
global: pyenv global 2.7
local: pyenv local system
shell: pyenv shell 3.5.0
分别切换不同场景的不同Python版本
(6)刷新:pyenv rehash
(7)which 和 whence见上述英文描述