在同时拥有python2及python3的Linux上利用virtualenvwrapper创建虚拟环境出现错误“/usr/bin/python: No module named virtualenvwrapper”

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.

 

原因是在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)"
posted @ 2021-03-16 14:59  Maybach  阅读(125)  评论(0编辑  收藏  举报