[root@localhost ~]# pip install virtualenv [root@localhost ~]# pip install virtualenvwrapper
~/.bashrc (如果出现/usr/bin/python: No module named virtualenvwrapper则加23行)
1 export WORKON_HOME=~/Envs 2 export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 3 export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv 4 source /usr/local/bin/virtualenvwrapper.sh
source ~/.bashrc #读入配置文件,立即生效
使用:
1.创建虚拟环境 mkvirtualenv
1 mkvirtualenv venv 2 mkvirtualenv --python=/usr/local/python3.5.3/bin/python venv
查看当前的虚拟环境目录
[root@localhost ~]# workon
py2
py3
切换到虚拟环境
[root@localhost ~]# workon py3
(py3) [root@localhost ~]#
退出虚拟环境
(py3) [root@localhost ~]# deactivate
[root@localhost ~]#
删除虚拟环境
rmvirtualenv venv
生成可打包环境:
当前的ENV都被修改为相对路径:
1 virtualenv --relocatable ./
2 echo $VIRTUAL_EN