安装虚拟环境的命令
sudo pip install virtualenv
sudo pip install virtualenvwrapper
# 1、创建目录用来存放虚拟环境
mkdir $HOME/.virtualenvs # $HOME代表家目录,用于保存虚拟环境产生的目录
# 2、打开~/.bashrc文件,并添加如下:
export WORKON_HOME=$HOME/.virtualenvs # 导入虚拟环境保存的目录
source /usr/local/bin/virtualenvwrapper.sh # 添加命令的路径
# 3、运行
source ~/.bashrc # 让命令生效
接下来如果出现下列报错的话,是因为在~/.bashrc这个文件中没有设置python解释器的路径
/usr/bin/python: No module named virtualenvwrapper
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
set properly.
需要插入如下代码
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
然后再运行命令
source ~/.bashrc
如果出现下面的输