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