• CentOS 7 创建Python虚拟环境(序列二)


    5.1安装python3
    yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel
    wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
    tar xf Python-3.7.2.tgz
    cd Python-3.7.2
    ./configure –prefix=/usr/local/Python37 –enable-optimizations
    make && make install
    echo “export PATH=/usr/local/Python37:/usr/local/Python37/scripts:$PATH” >> /etc/profile
    source /etc/profile
    ln -sf /usr/local/Python37/bin/python3 /usr/bin/python3
    ln -sf /usr/local/Python37/bin/pip3 /usr/bin/pip3

    5.2升级pip
    pip3 install –upgrade pip

    5.3安装虚拟环境
    pip3 install virtualenv
    ln -sf /usr/local/Python37/bin/virtualenv /usr/bin/virtualenv
    mkdir -p /usr/local/MyPy3Venv
    cd /usr/local/MyPy3Venv
    virtualenv py37venv

    5.4激活虚拟环境
    source /usr/local/MyPy3Venv/py37venv/bin/activate

    5.5退出虚拟环境执行命令:
    deactivate

    5.6验证pip3
    pip3 list –format=columns

    5.7安装管理虚拟环境virtualenvwrappe工具
    #virtualenvwrapper是virtualenv的扩展管理包,用于更方便管理虚拟环境,安装之后并不能直接使用,我们需要配置之后才能使用相关命令
    pip3 install virtualenvwrapper
    #找到virtualenvwrapper.sh
    find / -name virtualenvwrapper.sh
    #配置virtualenvwrapper(也可把配置到~/.bash_profile中作为当前用户使用)
    echo “export WORKON_HOME=$HOME/.virtualenvs” >> /etc/profile
    echo “export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3” >> /etc/profile
    echo “source /usr/local/Python37/bin/virtualenvwrapper.sh” >> /etc/profile
    source /etc/profile

    5.8virtualenvwrappe工具使用
    #新建虚拟环境test并指定python版本python3
    mkvirtualenv test –python=python3
    #执行lsvirtualenv指令查看所有环境,环境test位于/root/.virtualenvs/test
    lsvirtualenv
    #在项目底下激活虚拟环境test (退出后激活)
    workon test
    #退出环境test
    deactivate
    #删除环境test
    rmvirtualenv test

    5.9安装python项目服务运行环境
    pip3 install gunicorn supervisor flask django

  • 相关阅读:
    python字符串操作
    老男孩购物车程序
    python数据类型,判断,循环
    Matplotlib 绘图参考手册
    numpy 基础知识
    numpy random 模块
    numpy 算术运算
    pandas 读写数据
    python 读写文本
    python--windows文件操作
  • 原文地址:https://www.cnblogs.com/xiaozengzeng/p/13709396.html
Copyright © 2020-2023  润新知