No module named virtualenvwrapper 虚拟环境报错
No module named virtualenvwrapper 虚拟环境报错
- 安装虚拟环境命令
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
如果出现下面的输出
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/initialize
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/premkvirtualenv
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/postmkvirtualenv
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/prermvirtualenv
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/postrmvirtualenv
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/predeactivate
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/postdeactivate
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/preactivate
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/postactivate
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/get_env_details
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/premkproject
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/postmkproject
表示虚拟环境的命令导入成功了,可以正常使用