【问题标题】:`which python` in virtualenvwrapper.sh screws up in arch linuxvirtualenvwrapper.sh 中的 `which python` 在 Arch linux 中搞砸了
【发布时间】:2012-04-13 04:49:11
【问题描述】:

在 arch linux 上,通过sudo pip2 install virtualenvwrapper 在系统范围内安装 virtualenvwrapper 并将其添加到我的用户的 .bash_profile 中,

 export WORKON_HOME=/home/myuser/.virtualenvs
 export PROJECT_HOME=/home/myuser/work
 source /usr/bin/virtualenvwrapper.sh

每当我启动一个新的 shell 窗口时都会出现一个错误:-

which: no python in (/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin/core_perl)
-bash: : command not found
virtualenvwrapper.sh: There was a problem running the initialization hooks. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON= and that PATH is set properly.

这可以追溯到 virtualenvwrapper.sh 脚本中的第 50 行:-

 47 # Locate the global Python where virtualenvwrapper is installed. 
 48 if [ "$VIRTUALENVWRAPPER_PYTHON" = "" ] 
 49 then 
 50     VIRTUALENVWRAPPER_PYTHON="$(\which python)" 
 51 fi 

并且是与 Arch linux 使用 python2 安装 python 2.7 的约定冲突的结果。

如果我将第 50 行修改为 which python2,一切都会正常运行,并且每次启动新 shell 时都不会看到错误消息。

解决此问题的适当方法是什么?我是否写了一个明确的检查当前操作系统是arch linux并引入一个if-else条件来使用virtualenvwrapper.sh中的哪个python2并将补丁发送给virtualenvwrapper作者?或者我可以在我的 Arch linux 机器上使用我的配置做些什么?

【问题讨论】:

    标签: python-2.x archlinux virtualenvwrapper


    【解决方案1】:

    Virtualenvwrapper 有变量 VIRTUALENVWRAPPER_PYTHON 和 VIRTUALENVWRAPPER_VIRTUALENV 指向你的 python 和 virtualenv 可执行文件。因此,在您的 .bash_profile 中,您可以编写如下内容:

    export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python2
    export VIRTUALENVWRAPPER_VIRTUALENV=/usr/bin/virtualenv2
    source /usr/bin/virtualenvwrapper.sh
    

    【讨论】:

      【解决方案2】:

      为了回答这个特定于拱门的 Python 怪癖(使用 python2 的约定),我专门创建了一个这样的软链接:-

      ln -s /usr/bin/python2 /usr/local/bin/python
      

      由于bash系统PATH环境变量中/usr/local/bin在/usr/bin之前,所以当我输入python,或者virtualenvwrapper.sh脚本在第50行引用which python时,我们就不会再遇到上面的情况了提到 virtualenvwrapper 冲突,一切都按预期工作。

      这样做的缺点是它可能会弄乱 Arch linux 设计的“python 3”(被认为是默认的 python 命令)约定。所以必须注意不要在我的目标框中使用与 python 3 相关的库或与 python 3 相关的包安装。

      【讨论】:

      • 这是一个很好的答案,对我来说它比 virtualenv 好得多。我只是有时需要它,因此我只在需要时创建链接,然后取消链接 /usr/local/bin/python
      【解决方案3】:

      我发现无需编辑/usr/bin/virtualenvwrapper.sh 脚本或创建新的符号链接。我只是错过了 python2 的 virtualenvwrapper 模块。我是这样安装的:

      pip2 install virtualenvwrapper
      

      并保留出口,这样魔法就完成了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-10-13
        • 2012-02-06
        • 1970-01-01
        • 2014-01-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多