Python——3.pyenv

在开发Python程序的时候,有时候可能需要在不同版本的Python上进行测试。pyenv就是这么一个管理多版本Python的工具。
pyenv的工作原理垫片(Shims),将它自己管理的Python目录插到环境变量的最前面,系统在搜索Python的时候第一个找到的就是pyenv管理的Python环境。这个插到最前面的路径就叫做垫片(shims)。

1.安装1

1.1 下载pyenv

https://github.com/pyenv/pyenv
[root@node2 soft]# wget https://github.com/pyenv/pyenv/archive/v1.2.16.zip
百度网盘:https://pan.baidu.com/s/1BOstXQEstIiS3bBe2oaUfw  提取码:2b85

1.2 解压

[root@node2 soft]# mkdir /share
[root@node2 soft]# yum install unzip zip && unzip -o v1.2.16.zip -d /share/ && mv /share/pyenv-1.2.16 /share/pyenv && cd /share/pyenv
[root@node2 pyenv]# ls
bin           COMMANDS.md  CONDUCT.md  LICENSE   plugins       pyenv.d    src                  test
CHANGELOG.md  completions  libexec     Makefile  pyenv-1.2.16  README.md  terminal_output.png
[root@node2 pyenv]# cd bin/
[root@node2 bin]# ls
pyenv

1.3 指定环境变量

[root@node2 bin]# mkdir -pv /share/lnhome 
[root@node2 bin]# ln -sf /share/pyenv /share/lnhome/pyenv 
[root@node2 bin]# echo 'export PYENV_HOME=/share/lnhome/pyenv' >> /etc/profile
[root@node2 bin]# echo 'export PATH=$PYENV_HOME/bin:$PATH'>>/etc/profile
[root@node2 bin]# echo 'export PYENV_HOME=/share/lnhome/pyenv' >> ~/.bashrc 
[root@node2 bin]# echo 'export PATH=$PYENV_HOME/bin:$PATH'>> ~/.bashrc 
[root@node2 bin]# source /etc/profile ~/.bashrc

1.4 测试

[root@master soft]# pyenv 
pyenv 1.2.15
Usage: pyenv <command> [<args>]

Some useful pyenv commands are:
   commands    List all available pyenv commands
   commands    List all available pyenv commands
   exec        Run an executable with the selected Python version
   global      Set or show the global Python version
   help        Display help for a command
   hooks       List hook scripts for a given pyenv command
   init        Configure the shell environment for pyenv
   local       Set or show the local application-specific Python version
   prefix      Display prefix for a Python version
   rehash      Rehash pyenv shims (run this after installing executables)
   root        Display the root directory where versions and shims are kept
   shell       Set or show the shell-specific Python version
   shims       List existing pyenv shims
   version     Show the current Python version and its origin
   --version   Display the version of pyenv
   version-file   Detect the file that sets the current pyenv version
   version-name   Show the current Python version
   version-origin   Explain how the current Python version is se

Lists all available pyenv commands.

[root@master pyenv]# pyenv commands
commands
completions
exec
global
help
hooks
init
local
prefix
rehash
root
shell
shims
version
--version
version-file
version-file-read
version-file-write
version-name
version-origin
versions
whence
which

为毛,没有inistall

2.安装2

2.1 下载并执行脚本

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

2.2 更新

[root@master ~]# pyenv update

2.3 卸载

[root@master ~]# rm -fr ~/.pyenv
~/.bashrc中删除
export PATH="~/.pyenv/bin: P A T H " e v a l " PATH" eval " (pyenv init -)"
eval “$(pyenv virtualenv-init -)”

2.4 全局变量和pyenv命令对应关系

pyenv shell对应PYENV_VERSION。
pyenv local对应当前目录的.python-version。
pyenv global对应~/.pyenv/version。

2.5 列出可安装的Python版本

[root@master ~]# pyenv install -l(–list)

2.6 安装version版本Python

[root@master ~]# pyenv install

2.7 卸载ersion版本Python

[root@master ~]# pyenv uninstall [-f|–force]

2.8 列出所有已安装的Python

[root@master ~]# pyenv versions

2.9 设置全局Python

[root@master ~]# pyenv global

2.10 设置当前目录下

[root@master ~]# pyenv local

2.11 设置shell使用的Python

[root@master ~]# pyenv shell

————Blueicex 2020/2/21 14:59 [email protected]

发布了118 篇原创文章 · 获赞 1 · 访问量 4511

猜你喜欢

转载自blog.csdn.net/blueicex2017/article/details/104427359