1. 安装 git,github 地址为 https://github.com/pyenv/pyenv-installer/
yum install git -y
2. 安装 python 编译依赖环境
yum -y install gcc make patch gdbm-devel openssl-devel sqlite-devel readline-devel zlib-devel bzip2-devel
3. 创建 python 用户用于搭建 pyenv 专用于 python 多版本管理环境
- useradd python
- passwd python
4. 安装 pyenv 环境
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
5. 在 python 用户的环境变量目录~/.bash_profile 下添加环境变量
- export PATH
- export PATH="/home/python/.pyenv/bin:$PATH"
- eval "$(pyenv init -)"
- eval "$(pyenv virtualenv-init -)"
6.python 查看版本命令: python --version
pyenv 命令:
- pyenv install -l #列出所有能安装的包
- pyenv help
- local #指定本地 pyenv 环境, 其目录下所有子目录都会递归继承其属性
- global #指定全局的环境
- shell #指定当前会话
- install #指定安装的版本
- uninstall #卸载指定的安装环境包
- rehash
- version #查看当前环境使用的 pyenv 版本
- versions #查看所有的存在的 pyenv 版本, 带 * 号的为当前的 pyenv 环境版本
- which
- whence
7.virtualenv 虚拟环境设置
- [python@node1 python3.5.3]$ pyenv versions
- system
- * 3.5.3 (set by /home/python/python3.5.3/.python-version)
- 3.6.2
- [python@node1 python3.5.3]$ pyenv virtualenv 3.5.3 3-5-3 #将 3.5.3 版本的 python 命名为 3-5-3 的别名
Requirement already satisfied: setuptools in /home/python/.pyenv /versions/3.5.3/envs/3-5-3/lib/python3.5/site-packages
Requirement already satisfied: pip in /home/python/.pyenv/versions/3.5.3/envs/3-5-3/lib/python3.5/site-packages
- [python@node1 python3.5.3]$ pyenv versions
- system
- 3-5-3
- * 3.5.3 (set by /home/python/python3.5.3/.python-version)
- 3.5.3/envs/3-5-3
- 3.6.2
- [python@node1 python3.5.3]$ pyenv local 3-5-3 #使用虚拟环境时前面多出了一个名称
- (3-5-3) [python@node1 python3.5.3]$ pyenv version
- 3-5-3 (set by /home/python/python3.5.3/.python-version)
- (3-5-3) [python@node1 python3.5.3]$
来源: http://www.bubuko.com/infodetail-2571807.html