pip安装虚拟环境的命令 :
~$:sudo pip install virtualenv
~$:sudo pip install virtualenvwrapper
注意:我在安装virtualenvwrapper时出现报错情况,应该是找到源,我使用的是:
~$:sudo pip install -i https://pypi.douban.com/simple virtualenvwrapper
安装成功。
安装完虚拟环境后,如果提示找不到mkvirtualenv命令,须配置环境变量:
# 1、创建目录用来存放虚拟环境 ~$:mkdir $HOME/.virtualenvs # 2、打开~/.bashrc文件,并添加如下两行: export WORKON_HOME=$HOME/.virtualenvs source /usr/local/bin/virtualenvwrapper.sh # 3、运行 ~$:source ~/.bashrc
指定解释器和解释器的版本
~$:mkvirtualenv -p python3 虚拟环境名称
注意:找不到python3解释器,看一下python3的文件位置:
~$:which python
/home/konghy/kvenv/bin/python
~$:mkvirtualenv -p /home/konghy/kvenv/bin/python3 虚拟环境名称
提示 :
- 创建虚拟环境需要联网
- 创建成功后, 会自动工作在这个虚拟环境上
- 工作在虚拟环境上, 提示符最前面会出现 “虚拟环境名称
至此已经全部完成安装命令,
可以使用workon看一下自己目前有创建的虚拟环境有哪些:
~$:workon (直接回车)
py2
py3
环境推出:(直接回车)
~$:deactivate
切换环境:
workon 虚拟环境
删除虚拟环境
rmvirtualenv venv