Linux:CentOS7
python:
系统默认python版本2.7,利用python启动
自己安装python版本3.8,利用python3启动
问题描述:
在上述环境中利用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.
https://blog.csdn.net/Sun_White_Boy/article/details/81144924
原因是在virtualenvwrapper.sh中有以下代码
# Locate the global Python where virtualenvwrapper is installed. if [ "${VIRTUALENVWRAPPER_PYTHON:-}" = "" ] then VIRTUALENVWRAPPER_PYTHON="$(command \which python)" fi
所以,在virtualenvwrapper初始化时,命令“which python”调用的是python2.7,而我的virtualenvwrapper是由pip3下载,所以会有错误“No module named virtualenvwrapper”
解决办法:
直接修改其command语句
VIRTUALENVWRAPPER_PYTHON="$(command \which python3)"
参考文章:https://blog.csdn.net/Sun_White_Boy/article/details/81144924