工作生活

Python pyenv

2019-07-01  本文已影响0人  Alexander_Zz

一、Pyenv 简介

1.1 官网

https://github.com/pyenv/pyenv

1.2 简介

是一款 Python 多版本管理工具,可将多个 Python 版本进行隔离,使多版本可完美共存,无冲突


二、Pyenv 安装

2.1 基础环境
2.2 安装步骤
# 安装 git
~]# yum install -y git

# 安装 Python 依赖
~]# yum install -y gcc make patch gdbm-devel openssl-devel sqlite-devel readline-devel zlib-devel bzip2-devel

# 创建 Python 用户
~]# useradd python
~]# echo 'python' | passwd --stdin python

# 安装 pyenv,使用 python 用户登录
~]$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv

# 配置环境变量
~]$ vim ./.bash_profile

export PATH="/home/python/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

# 安装 pyenv-virtualenv
~]$ git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv

# 重读环境变量
~]$ . .bash_profile

三、pyenv 使用入门

3.1 版本控制
3.2 虚拟环境
# 创建虚拟环境
~]$ pyenv virtualenv 3.6.6 py3.6.6
Looking in links: /tmp/tmprj5rgjgo
Requirement already satisfied: setuptools in /home/python/.pyenv/versions/3.6.6/envs/py3.6.6/lib/python3.6/site-packages (39.0.1)
Requirement already satisfied: pip in /home/python/.pyenv/versions/3.6.6/envs/py3.6.6/lib/python3.6/site-packages (10.0.1)

# 查看当前所有版本 
~]$ pyenv versions
* system (set by /home/python/.pyenv/version)
  3.6.6
  3.6.6/envs/py3.6.6
  3.6.8
  py3.6.6

# 添加本地虚拟环境
~]$ mkdir python/example/test -p
~]$ cd python/example/test
test]$ pyenv local py3.6.6

# 此时提示符前会出现虚拟环境标识 (py3.6.6)
test]$ pyenv version
py3.6.6 (set by /home/python/python/example/test/.python-version)
上一篇 下一篇

猜你喜欢

热点阅读