• virtualenvwrapper.sh报错: There was a problem running the initialization hooks.解决


    由于在ubuntu环境下,将python做与python3.6做了软链接(ln -s python python3.6),并且pip也被我做了软链接,所以导致用pip安装virtualenvwrapper之后,在source启动virtualenvwrapper.sh时以及workon 虚拟环境时总是报错:

    1 ./virtualenvwrapper.sh: line 230: : command not found
    2 virtualenvwrapper.sh: There was a problem running the initialization hooks.
    3 
    4 If Python could not import the module virtualenvwrapper.hook_loader,
    5 check that virtualenvwrapper has been installed for
    6 VIRTUALENVWRAPPER_PYTHON= and that PATH is
    7 set properly.

    这是根据提示230行的语句:

    1 "$VIRTUALENVWRAPPER_PYTHON" -m 'virtualenvwrapper.hook_loader' 

    结合错误信息与提示找到的语句,猜测应该是VIRTUALENVWRAPPER_PYTHON这里有问题,然后在virtualenvwrapper.sh文件中查找VIRTUALENVWRAPPER_PYTHON,发现了关键点:

    1 # Locate the global Python where virtualenvwrapper is installed.
    2 if [ "${VIRTUALENVWRAPPER_PYTHON:-}" = "" ]
    3 then
    4     VIRTUALENVWRAPPER_PYTHON="$(command which python3)"    # 原本是写的which python,这里贴出来的是我修改为python3后的。
    5 fi

    VIRTUALENVWRAPPER_PYTHON是用来(Locate the global Python where virtualenvwrapper is installed.)定位哪个python下面安装了virtualenvwrapper的。原本指定的位置是python,也就是2.7版本的。鉴于之前我使用python3.6安装的,所以此处要改成python3。然后这个错误就消失了。


    使用virtualenvwrapper的好处是不用每次使用source /xxx/虚拟环境/bin/activate来启动虚拟环境了,在~/.bashrc配置一下,日后开启虚拟环境直接可以用workon命令即可,具体操作步骤,前提是你已经安装了python-virtualenv了:

    # Setup:
    #  1. Create a directory to hold the virtual environments.
    #     (mkdir $HOME/.virtualenvs).
    #  2. Add a line like "export WORKON_HOME=$HOME/.virtualenvs"
    #     to your .bashrc.
    #  3. Add a line like "source /path/to/this/file/virtualenvwrapper.sh"
    #     to your .bashrc.
    #  4. Run: source ~/.bashrc
    #  5. Run: workon
    #  6. A list of environments, empty, is printed.
    #  7. Run: mkvirtualenv temp
    #  8. Run: workon
    #  9. This time, the "temp" environment is included.
    # 10. Run: workon temp
    # 11. The virtual environment is activated.

  • 相关阅读:
    POI使用介绍
    Git的使用简介
    SOA架构搭建---duboo+zookeeper+SSM实现
    分布式事务介绍
    兼容安卓微信调用摄像头
    cookie
    js对手机软键盘的监听
    input 改变placeholder默认样式
    VisualVm使用JMX的方式连接远程JVM
    update批量根据条件更新
  • 原文地址:https://www.cnblogs.com/cpl9412290130/p/10019231.html
Copyright © 2020-2023  润新知