(坑集)virtualenvwrapper.sh: There was a problem running the initialization hooks. If Python could not

virtualenvwrapper配置报错
在安装好virtualenvwrapper之后,需要在~/.bashrc中配置,把vw的.sh文件添加进去,还可以选择修改虚拟环境默认保存的位置。
首先在编辑.bashrc之前,你需要知道virtualenvwrapper.sh文件的路径,使用下面的命令查找。

sudo find / -name virtualenvwrapper.sh

下面是我的查找结果
在这里插入图片描述
因为我是直接安装在我的用户路径下的,所以如果你是安装在根目录下,结果应该是/usr/local/bin/virtualenvwrapper.sh。

得知路径之后就可以在~/.bashrc文件中添加下面配置

export WORKON_HOME=$HOME/virtualenvs # 配置虚拟环境的保存位置 $HOME是用户的主目录
source /home/God/.local/bin/virtualenvwrapper.sh # 配置virtualenvwrapper命令的脚本 

第一条配置可以随你的喜爱去更改,但是第二条配置需要使用刚才获取路径,只有命令脚本路径正确才可在linux中直接使用virtualenvwrapper中的命令。

修改.bashrc文件后,需要重新加载.bashrc文件

source ~/.bashrc

重点!!!

如果你的环境是python3,重新加载后,可能会出现这样类似的错误

/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

脚本会默认使用python2环境,但是virtualenvwrapper装在了python3环境中,所以会有上面的报错。

解决办法:

直接将VIRTUALENVWRAPPER_PYTHON默认值修改为/usr/bin/python3即可

# Locate the global Python where virtualenvwrapper is installed.
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
if [ "$VIRTUALENVWRAPPER_PYTHON" = "" ] then
    VIRTUALENVWRAPPER_PYTHON="$(command \which python)"
fi

修改后,按照上面步骤,重新加载下virtualenvwrapper.sh即可解决问题。

  • 8
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值