# 1. ubuntu下打开终端出现/usr/bin/python: No module named virtualenvwrapper......错误代码提示
原因是因为上午时安装虚拟环境的原因
- 安装virtualenv
sudo pip install virtualenv - 安装virtualenvwrapper
sudo pip install virtualenvwrapper
错误提示
/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
由于我的电脑上有两个python环境 python2.7和python3.6 在安装时使用的是sudo pip3 install virtualenvwrapper 在我运行的时候默认使用的是python2.7,但在python2.7中不存在对应的模块
在usr/local/bin下存在这个文件virtualenvwrapper.sh 打开用sudo vi virtualenvwrapper.sh 增加一行 VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
当不存在VIRTUALENVWRAPPER_PYTHON环境时,会默认选择使用which python(我这里默认是python2.7), 所以需要增加此环境变量
if [ "${VIRTUALENVWRAPPER_PYTHON:-}" = "" ]
then
VIRTUALENVWRAPPER_PYTHON="$(command \which python)"
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
fi
保存并退出,再次打开恢复正常
本文参考来自博客 virtualenvwrapper配置