• 在centos上使用pyenv管理python及虚拟环境


    1. 准备工作

            1.1 安装依赖包

    yum install gcc zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel tk-devel libffi-devel xz-devel
    

            1.2. 如果没有git环境的话,还需要下载git

    yum install -y git
    

    2. 下载pyenv(git方式)

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

    3. 将环境变量添加至配置文件中

    1. [root@VM-0-12-centos ~]# cat .bash_profile
    2. # .bash_profile
    3. # Get the aliases and functions
    4. if [ -f ~/.bashrc ]; then
    5. . ~/.bashrc
    6. fi
    7. # User specific environment and startup programs
    8. export PYENV_ROOT="$HOME/.pyenv"
    9. export PATH="$PYENV_ROOT/bin:$PATH"
    10. eval "$(pyenv init --path)"
    11. eval "$(pyenv init -)"
    12. eval "$(pyenv virtualenv-init -)"
    13. [root@VM-0-12-centos ~]#

    4. pyenv的基本使用

            4.1 查看pyenv可下载的python版本,同时测试pyenv是否安装成功

    1. [root@VM-0-12-centos ~]# pyenv install --list
    2. Available versions:
    3. 2.1.3
    4. 2.2.3
    5. 2.3.7
    6. 2.4.0
    7. ...
    8. [root@VM-0-12-centos ~]#

            4.2 下载所需要的python版本

    1. pyenv install 3.9.1 -v
    2. // 3.9.1代表python的版本号
    3. // -v 表示安装过程可视化

            4.3 下载完成之后,查看所有已安装的python版本

    1. [root@VM-0-12-centos ~]# pyenv versions
    2. * system (set by /root/.pyenv/version)
    3. 3.6.8
    4. 3.7.2
    5. 3.8.6
    6. 3.9.1
    7. [root@VM-0-12-centos ~]#

    5. 配置虚拟环境(pyenv-virtualenv)

            5.1 下载(git方式)

     git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv

            5.2 指定python版本创建虚拟环境

    1. [root@VM-0-12-centos ~]# pyenv virtualenv 3.9.1 env391
    2. Looking in links: /tmp/tmpzbwbypcj
    3. Requirement already satisfied: setuptools in /root/.pyenv/versions/3.9.1/envs/env391/lib/python3.9/site-packages (49.2.1)
    4. Requirement already satisfied: pip in /root/.pyenv/versions/3.9.1/envs/env391/lib/python3.9/site-packages (20.2.3)
    5. [root@VM-0-12-centos ~]#

            5.3 列出虚拟环境

    1. [root@VM-0-12-centos ~]# pyenv virtualenvs
    2. 3.8.6/envs/env386 (created from /root/.pyenv/versions/3.8.6)
    3. 3.9.1/envs/env391 (created from /root/.pyenv/versions/3.9.1)
    4. env386 (created from /root/.pyenv/versions/3.8.6)
    5. env391 (created from /root/.pyenv/versions/3.9.1)
    6. [root@VM-0-12-centos ~]#

            5.4 进入虚拟环境并查看python版本

    1. [root@VM-0-12-centos ~]# pyenv activate env391
    2. pyenv-virtualenv: prompt changing will be removed from future release. configure `export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
    3. (env391) [root@VM-0-12-centos ~]# python -V
    4. Python 3.9.1
    5. (env391) [root@VM-0-12-centos ~]# pyenv activate env386
    6. pyenv-virtualenv: prompt changing will be removed from future release. configure `export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
    7. (env386) [root@VM-0-12-centos ~]# python -V
    8. Python 3.8.6
    9. (env386) [root@VM-0-12-centos ~]#

            5.5 退出虚拟环境

    1. (env386) [root@VM-0-12-centos ~]# pyenv deactivate
    2. [root@VM-0-12-centos ~]#

  • 相关阅读:
    C认证笔记 - 计算机通识 - 进制转换
    【vue】牛客专题训练02
    中科芯与IAR共建生态合作,IAR集成开发环境全面支持CKS32系列MCU
    教你一文解决 js 数字精度丢失问题
    VSCode remote-ssh 连接远端服务器失败
    尚硅谷SQL|数据库的创建,修改与删除
    异形双柱体阵列纳米粒:球形纳米粒/圆盘形纳米粒子/盘状纳米粒子/棒状纳米粒子
    CentOS7安装MySQL8(Red Hat版)
    Java基础入门·对存储文件File的相关操作
    百度Apollo自动驾驶
  • 原文地址:https://blog.csdn.net/qq_42598133/article/details/127787422