云服务器安装 virtualenvwrapper.sh: There was a problem running the initialization hooks 解决

云服务器安装了 virtualenvwrapper,配置 .bashrc后 重启.bashrc报错

[zhangxiong@iZwz9f39q73rnvtdlfy150Z ~]$ source ~/.bashrc
which: no python in (/home/zhangxiong/.local/bin:/home/zhangxiong/bin:/usr/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.el8_4.x86_64/bin)
bash: : 未找到命令
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= and that PATH is
set properly.

看看.bashrc的内容:

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
then
    PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
export PATH

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions


export WORKON_HOME=/home/zhangxiong/.virtualenv
source /usr/local/bin/virtualenvwrapper.sh

最后两行是我加的,很明显问题就出在这.

我们再去看看 virtualenvwrapper.sh

# Locate the global Python where virtualenvwrapper is installed.
if [ "${VIRTUALENVWRAPPER_PYTHON:-}" = "" ]
then
    VIRTUALENVWRAPPER_PYTHON="$(command \which python)"
fi

# Set the name of the virtualenv app to use.
if [ "${VIRTUALENVWRAPPER_VIRTUALENV:-}" = "" ]
then
    VIRTUALENVWRAPPER_VIRTUALENV="virtualenv"
fi

VIRTUALENVWRAPPER_PYTHON="$(command \which python)"看到这里, 我已经找到问题了.
因为我仅安装了python3环境,切配置了环境变量.

[zhangxiong@iZwz9f39q73rnvtdlfy150Z ~]$ which python3
/usr/bin/python3
[zhangxiong@iZwz9f39q73rnvtdlfy150Z ~]$ which python
/usr/bin/which: no python in (/home/zhangxiong/.local/bin:/home/zhangxiong/bin:/usr/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.el8_4.x86_64/bin)

所以我只需要将 “$(command \which python)” 中的python改为python3就好了.

改完重试:

[zhangxiong@iZwz9f39q73rnvtdlfy150Z ~]$ source ~/.bashrc
virtualenvwrapper.user_scripts creating /home/zhangxiong/.virtualenv/premkproject
virtualenvwrapper.user_scripts creating /home/zhangxiong/.virtualenv/postmkproject
virtualenvwrapper.user_scripts creating /home/zhangxiong/.virtualenv/initialize
virtualenvwrapper.user_scripts creating /home/zhangxiong/.virtualenv/premkvirtualenv
virtualenvwrapper.user_scripts creating /home/zhangxiong/.virtualenv/postmkvirtualenv
virtualenvwrapper.user_scripts creating /home/zhangxiong/.virtualenv/prermvirtualenv
virtualenvwrapper.user_scripts creating /home/zhangxiong/.virtualenv/postrmvirtualenv
virtualenvwrapper.user_scripts creating /home/zhangxiong/.virtualenv/predeactivate
virtualenvwrapper.user_scripts creating /home/zhangxiong/.virtualenv/postdeactivate
virtualenvwrapper.user_scripts creating /home/zhangxiong/.virtualenv/preactivate
virtualenvwrapper.user_scripts creating /home/zhangxiong/.virtualenv/postactivate
virtualenvwrapper.user_scripts creating /home/zhangxiong/.virtualenv/get_env_details

OK,成功!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值