Centos7 安装 pyenv 完美管理多版本Python

Centos7 安装 pyenv 完美管理多版本Python

安装依赖

yum groupinstall "Development Tools"

安装最新版pyenv

git clone https://github.com/pyenv/pyenv.git ~/.pyenv

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile

echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bash_profile

重新进入shell

exec "$SHELL"
#我执行这条好像没用,解决方法是执行完这条命令后断开ssh连接再重新连接就可以了

查看pyenv版本

[root@www ~]# pyenv
pyenv 1.2.22-19-g569992f
Usage: pyenv <command> [<args>]

Some useful pyenv commands are:
   commands    List all available pyenv commands
   exec        Run an executable with the selected Python version
   global      Set or show the global Python version(s)
   help        Display help for a command
   hooks       List hook scripts for a given pyenv command
   init        Configure the shell environment for pyenv
   install     Install a Python version using python-build
   local       Set or show the local application-specific Python version(s)
   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
   uninstall   Uninstall a specific Python version
   version     Show the current Python version(s) 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 set
   versions    List all Python versions available to pyenv
   whence      List all Python versions that contain the given executable
   which       Display the full path to an executable

See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/pyenv/pyenv#readme

安装Python

pyenv install --list    #版本列表
pyenv install 3.8.7 -v  #在线安装指定版本:例如3.8.7

设置版本控制

pyenv version   #显示当前版本
pyenv versions  #显示所有可用版本及当前版本
pyenv global 3.8.7  #global为全局设置版本,不建议随意使用
pyenv shell 3.8.7   #shell为当前会话设置版本,关闭失效
pyenv local 3.8.7   #local为当前目录设置版本(递归继承)

这篇文章有用吗?

点击星号为它评分!

平均评分 0 / 5. 投票数: 0

到目前为止还没有投票!成为第一位评论此文章。

发表评论