python virtualenv install

安装virtualenv

  • 方式一: yum

    1
    2
    3
    4
    [root@localhost ~]# rpm -qa python
    python-2.7.5-48.el7.x86_64

    [root@localhost ~]# yum -y install python-virtualenv
  • 方式二: pip

    1
    2
    3
    4
    5
    [root@localhost ~]# rpm -qa python
    python-2.7.5-48.el7.x86_64

    [root@localhost ~]# yum -y install python2-pip
    [root@localhost ~]# pip install virtualenv

使用virtualenv

  • 创建一个虚拟空间

    1
    [root@localhost ~]# virtualenv -p /usr/bin/python2.7 myenv
  • 切换到虚拟空间

    1
    2
    [root@localhost ~]# source myenv/bin/activate
    (myenv)[root@localhost ~]#
  • 退出虚拟空间

    1
    2
    (myenv)[root@localhost ~]# deactivate
    [root@localhost ~]#