• 在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 ~]#

  • 相关阅读:
    计算机毕业设计之java+ssm的网上订餐系统
    css媒体查询新特性
    JS原型对象prototype
    对于补码的个人理解
    Chrome扩展开发实战:网页图片抓取,打造专属自己的效率插件
    【 java 面向对象】this和super关键字
    MySQL(基础篇)——函数、约束
    醛肽:Gly-Phe-Gly-aldehyde、102579-48-6
    华为OD机考算法题:分奖金
    LeetCode每日一题(1233. Remove Sub-Folders from the Filesystem)
  • 原文地址:https://blog.csdn.net/qq_42598133/article/details/127787422