云服务器安装了 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,成功!
版权声明:本文为Arvin_zx原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。