virtualenv安装
virtualenv
一、安装全新的vitrualenv系统
#安装virtualenv
[root@node3 ~]# pip install virtualenv #稳定版本
[root@node3 ~]# pip install virtualenv==15.0.1 #实验版本
[root@node3 ~]# pip freeze
#创建一个项目
[root@node3 ~]# virtualenv test
#进入虚拟环境
[root@node3 ~]# source test/bin/activate
#虚拟环境中用pip安装软件
(test) [root@node3 ~]# pip freeze
(test) [root@node3 ~]# pip list
(test) [root@node3 ~]# pip install django==1.9.5
(test) [root@node3 ~]# pip install pymysql==0.7.4
(test) [root@node3 ~]# pip list
#退出虚拟环境
(test) [root@node3 ~]# deactivate
注意:
#windows中进入虚拟环境
[root@node3 ~]# test/Scripts/activate
二、本地通道
把本地的环境直接复制一份到虚拟环境中
[root@node3 ~]# virtualenv test1 --system-site-packages #创建本地通道
[root@node3 ~]# source test1/bin/activate #linux
[root@node3 ~]# pip freeze
[root@node3 ~]# test1/Scripts/activate #windows
三、多版本python在pyenv切换时,virtualenv需要重新安装
1.virtualenv是python2.7安装的,即使pyenv切换3.5.1进入虚拟环境依然是2.7.10
xiaozhiqi@uplooking:~$ source blog_env/bin/activate
(blog_env) xiaozhiqi@uplooking:~$ python
Python 2.7.10 (default, Oct 14 2015, 16:09:02)
[GCC 5.2.1 20151010] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
(blog_env) xiaozhiqi@uplooking:~$ deactivate
xiaozhiqi@uplooking:~$ python
Python 3.5.1 (default, Jun 2 2016, 15:44:34)
[GCC 5.2.1 20151010] on linux
Type "help", "copyright", "credits" or "license" for more information.
2.virtualenv是python2.7安装的,即使pyenv切换3.5.1进入虚拟环境依然是2.7.10
xiaozhiqi@uplooking:~$ python
Python 3.5.1 (default, Jun 2 2016, 15:44:34)
[GCC 5.2.1 20151010] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
xiaozhiqi@uplooking:~$ source blog_env/bin/activate
(blog_env) xiaozhiqi@uplooking:~$ python
Python 3.5.1 (default, Jun 2 2016, 15:44:34)
[GCC 5.2.1 20151010] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

浙公网安备 33010602011771号