1.CentOS 7系统 Pyenv 管理 Python环境
Pyenv 是一款解决 Python 多版本环境使用的管理工具。通过 pyenv 我们可以同时编译安装部署多个 Python 环境,方便多 python 版本开发调试项目。
①通过安装git方式安装Pyenv
[python@localhost ~]$ su -l root
Password:
Last login: Tue Apr 2 16:07:47 CST 2019 on pts/0
[root@localhost ~]# yum install git
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.cn99.com
* updates: mirrors.cn99.com
Package git-1.8.3.1-20.el7.x86_64 already installed and latest version
Nothing to do
[root@localhost ~]# exit
logout
[python@localhost ~]$ git clone https://github.com/pyenv/pyenv.git .pyenv
Cloning into '.pyenv'...
remote: Enumerating objects: 81, done.
remote: Counting objects: 100% (81/81), done.
remote: Compressing objects: 100% (45/45), done.
remote: Total 16818 (delta 37), reused 61 (delta 28), pack-reused 16737
Receiving objects: 100% (16818/16818), 3.29 MiB | 463.00 KiB/s, done.
Resolving deltas: 100% (11379/11379), done.
[python@localhost ~]$ ls -adl .pyenv
drwxrwxr-x. 11 python python 4096 Apr 2 16:13 .pyenv
[python@localhost ~]$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
[python@localhost ~]$
[python@localhost ~]$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
[python@localhost ~]$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc
[python@localhost ~]$ pyenv
bash: pyenv: command not found...
[python@localhost ~]$
[python@localhost ~]$ source .bashrc
[python@localhost ~]$ pyenv
pyenv 1.2.9-35-gb610909
Usage: pyenv <command> [<args>]
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 <command>` for information on a specific command.
For full documentation, see: https://github.com/pyenv/pyenv#readme
②通过pyenv编译安装Python环境
pyenv install --list列出当前pyenv工具支持的python版本。
[root@VM-4-2-centos ~]# pyenv install --list
安装python版本
[root@VM-4-2-centos ~]# pyenv install -v 3.8.5
显示python安装版本
[root@VM-4-2-centos ~]# pyenv versions
指定python版本
[root@VM-4-2-centos ~]# pyenv shell 3.8.5