python多版本管理器pyenv

倾然丶 夕夏残阳落幕 提交于 2019-12-16 19:13:46

查看Linux版本```

[root@web ~]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 
[root@web ~]# uname -a
Linux web 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
1 [root@web ~]# cat /etc/redhat-release 
2 CentOS Linux release 7.6.1810 (Core) 
3 [root@web ~]# uname -a
4 Linux web 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

 

  


```

安装依赖```
[root@web ~]# yum -y install gcc zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel git xorg-x11-server-Xvfb bzip gtk3 gtk2
```

#### 安装pyenv
```
[root@web ~]# curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
```

#### 配置环境变量
```
[root@web ~]# cd /root
[root@web ~]# cp .bash_profile .bash_profile.bak
[root@web ~]# vim .bash_profile
#pyenv
export PATH="~/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
[root@web ~]# source .bash_profile
```

#### 系统自带python版本为2.7.5
```
[root@web ~]# python -V
Python 2.7.5
```

#### 安装的pyenv版本为1.2.15
```
[root@web ~]# pyenv -v
pyenv 1.2.15
```

#### 升级pyenv命令
```
[root@web ~]# pyenv update
```

#### 查看可用的python版本有哪些
```
[root@web ~]# pyenv install --list
```

#### 安装python3.6.4、python2.7.2和python3.6.7
```
[root@web ~]# pyenv install 3.6.4
[root@web ~]# pyenv install 2.7.2
[root@web ~]# pyenv install 3.6.7
```

#### 查看安装的python版本有哪些
```
[root@web ~]# pyenv versions
* system (set by /root/.pyenv/version)
2.7.2
3.6.4
3.6.7
[root@web ~]#
```

#### 配置root用户的python版本为3.6.4
```
[root@web ~]# cd /root/
[root@web ~]# pyenv virtualenv 3.6.4 root364
[root@web ~]# pyenv activate root364
[root@web ~]# pyenv global 3.6.4
(root364) [root@web ~]# python -V
Python 3.6.4
```

#### 去除当前使用的virtualenv
```
(root364) [root@web ~]# pyenv deactivate
[root@web ~]#
```

#### 删除某个virtualenv
```
[root@web ~]# pyenv virtualenv-delete root364
pyenv-virtualenv: remove /root/.pyenv/versions/3.6.4/envs/root364? y
[root@web ~]#
```

#### 设置/tmp目录的pyenv环境为python3.6.7
```
[root@web ~]# cd /tmp/
[root@web tmp]# pyenv virtualenv 3.6.7 tmp367
Looking in links: /tmp/tmpshtqhsk6
Requirement already satisfied: setuptools in /root/.pyenv/versions/3.6.7/envs/tmp367/lib/python3.6/site-packages (39.0.1)
Requirement already satisfied: pip in /root/.pyenv/versions/3.6.7/envs/tmp367/lib/python3.6/site-packages (10.0.1)
[root@web tmp]# pyenv activate tmp367
[root@web tmp]# pyenv local tmp367
(tmp367) [root@web tmp]# python -V
Python 3.6.7
(tmp367) [root@web tmp]#
```

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!