如何使用pyenv切换python版本

python2到python3版本跨度很大,函数库和方法都有很大不同。如果一台机器上有两个或以上版本的python,没有一个版本管理工具,会造成python版本的混乱。而且切换起来相当麻烦,本文讲述如何通过pyenv切换python版本

工具/原料

  • pvenv

  • centos7.2_x64

方法/步骤

  1. 屏幕输入pyenv命令,会看到如下可以使用的命令

       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 executabl

    如何使用pyenv切换python版本

  2. 使用pyenv install --list命令获取可以安装的python版本列表

    如何使用pyenv切换python版本

  3. 使用pyenv install -v 2.1.3,带上版本号2.1.3就能进行自动安装该版本。使用pyenv 另外一个好处就是能很方便的安装python历史版本

    如何使用pyenv切换python版本

  4. 使用pyenv versions命令查看已经安装的python版本,和当前python版本2.7.14 (set by /root/.pyenv/version)

    如何使用pyenv切换python版本

  5. 使用pyenv global 3.6.3切换到3.6.3

    如何使用pyenv切换python版本

  6. 使用pyenv global 2.1.3切换到2.1.3

    可以很方便的在各个python版本之间来回切换并能很容易的找到python很“古老”的版本

    如何使用pyenv切换python版本

  7. 参考文献:
    https://jingyan.baidu.com/article/7908e85cbe7d05af481ad2dc.html