Python多版本管理器pyenv

1.查看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

2.安装依赖

[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

3.安装pyenv

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

4.配置环境变量

[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

5.系统自带python版本为2.7.5

[root@web ~]# python -V
Python 2.7.5

6.安装的pyenv版本为1.2.15

[root@web ~]# pyenv -v
pyenv 1.2.15

7.升级pyenv命令

[root@web ~]# pyenv update

8.查看可用的python版本有哪些

[root@web ~]# pyenv install --list

9.安装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

10.查看安装的python版本有哪些

[root@web ~]# pyenv versions
* system (set by /root/.pyenv/version)
  2.7.2
  3.6.4
  3.6.7
[root@web ~]#  

11.配置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

12.去除当前使用的virtualenv

(root364) [root@web ~]# pyenv deactivate
[root@web ~]# 

13.删除某个virtualenv

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

14.设置/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]# 
上一篇:Python多版本管理器pyenv


下一篇:docker镜像的导入和导出