CentOS 7 Installation pyenv, deployment of Python isolated isolated environment

Source: Internet
Author: User
Tags virtual environment virtualenv

Installation Environment: CentOS 7
Install pyenv to Local
[[email protected]_7 cache]# git clone git://github.com/yyuu/pyenv.git   ~/.pyenv系统要先安装 git :如果没有,则直接yum 安装: yum  install  -y   
Provide environment configuration and take effect for pyenv
[[email protected]_7 cache]# cat  ~/.bashrc# .bashrc# User specific aliases and functionsalias rm=‘rm -i‘alias cp=‘cp -i‘alias mv=‘mv -i‘# Source global definitionsif [ -f /etc/bashrc ]; then    . /etc/bashrcfiexport PYENV_ROOT="$HOME/.pyenv"export PATH="$PYENV_ROOT/bin:$PATH"eval "$(pyenv init -)"添加最后的三行配置,保存文件,source  ~/.bashrc  使配置生效或者 exec  $SHELL -l
Environment for installing the system
[[email protected]_7 cache]# yum groupinstall "Development Tools"  -y[[email protected]_7 cache]# yum install -y python-devel libevent-devel python-pip gcc xz-devel openssl-devel readline-devel sqlite-devel bzip2-devel
List the Python versions you can install
[[email protected]_7 cache]# pyenv install --list
Install Python 3.5.2
因为 pyenv 是先将 python 安装包下载到 ~/.pyenv/cache/  目录,然后校验 md5值,再安装的,所以,如果用 pyenv  install  3.5.2 -v  的命令安装 python 比较慢,则可以将python-3.5.2 下载到 cache/ 目录,再用 pyenv  install 3.5.2  -v 命令安装。例如:[[email protected]_7 cache]# wget http://mirrors.sohu.com/python/3.5.2/Python-3.5.2.tar.xz -P ~/.pyenv/cache/在搜狐的镜像下载 Python-3.5.2.tar.xz 到 cache/ 目录然后:[[email protected]_7 cache]# pyenv install 3.5.2 -v速度会比较快
After the installation is complete, you need to refresh Pyenv
[[email protected]_7 cache]# pyenv rehash再查看系统中的 python 版本:[[email protected]_7 cache]# pyenv versions* system (set by /root/.pyenv/version)  3.5.2
Set up a specific Python version in a specific directory
pyenv的global子命令用于设定全局的版本,local子命令用于设置当前工作目录的特定python版本,version则用于查看当前正在使用的版本,新建两个目录,分别设置各自使用的版本例如: 设置在 ~/py35 目录使用 python3.5.2 [[email protected]_7 py35]# pwd/root/py35[[email protected]_7 py35]# pyenv local 3.5.2[[email protected]_7 py35]# pyenv local3.5.2[[email protected]_7 py35]# python -VPython 3.5.2切换到其他目录:[[email protected]_7 ~]# python -VPython 2.7.5
Delete the Python version in the current directory
要删除前面的 local 设置,只需要使用 --unset 或者 将目录下的 .python-version 文件删除[[email protected]_7 py35]# pyenv local --unset[[email protected]_7 py35]# python  -VPython 2.7.5变回系统默认的 2.7.5 版本了通过删除 .python-version 文件,取消特定目录使用特定 python 版本:[[email protected]_7 py35]# rm -rf .python-version[[email protected]_7 py35]# ls[[email protected]_7 py35]# pyenv localpyenv: no local version configured for this directory[[email protected]_7 py35]# python -VPython 2.7.5
Installing the Pyenv-virtualenv Plugin

Pyenv virtualenv is a pyenv plug-in that provides an isolated virtual environment for the Python version of the pyenv setup, and after setting up the virtual environment, third-party libraries and modified library search paths installed under this directory will not affect other environments, which are equivalent to a sandbox environment and do not affect each other.
Installing the Pyenv-virtualenv Plugin

[[email protected]_7 py35]#  git clone git://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
Re-loading the environment
exec  $SHELLpyenv-virtualenv会为pyenv引入一些新的命令,例如 virtualenv/virtualenv-delete 用于创建/删除虚拟环境,virtualenvs用于列出所有的虚拟环境,activate /deactivate用于激活和禁用虚拟环境
Create a virtual environment
[[email protected]_7 ~]# mkdir venv35[[email protected]_7 ~]# cd venv35[[email protected]_7 venv35]# ls[[email protected]_7 venv35]# pyenv virtualenv 3.5.2 env35查看可用的版本:[[email protected]_7 venv35]# pyenv versions* system (set by /root/.pyenv/version)  3.5.2  3.5.2/envs/env35  env35在此虚拟环境目录下面安装 ipython,切换到其他设定的版本目录中无法使用,说明是相互隔离的pyenv-virtualenv 只需要记住三条命令:pyenv virtualenv 3.5.2 env35     #创建一个 Python 版本为 3.5.2 的环境, 环境叫做 envpyenv activate env35  #激活 env 这个环境, 此时 Python 版本自动变为 3.3.0, 且是独立环境pyenv deactivate              #离开已经激活的环境

CentOS 7 Installation pyenv, deployment of Python isolated isolated environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.