【问题标题】:zc.buildout is using the wrong pythonzc.buildout 使用了错误的 python
【发布时间】:2011-11-28 13:09:41
【问题描述】:

我正在使用 zc.buildout 生成一个名为“test”的脚本。我正在使用该脚本来调用我自己的测试运行器。 (可用于构建的测试运行器尚未使用 Python 2.7 中的新“发现”功能。)

无论如何,这是我的 .cfg 文件中的相关部分:

[test]
recipe = buildout_script
template = runtests.sh.in
target = test

这是我的 runtests.sh.in 模板的样子

#!/bin/bash

python %(directory)s/src/runtests.py

这是作为 bin/test 放置在我的 bin 文件夹中的结果输出。

!/bin/bash

python /Users/myname/projects/myproject/trunk/www/src/desktop/src/runtests.py

当我执行这个脚本时,它使用的是系统 Python 而不是我 bin 文件夹中的 Python。

我的 .cfg 文件中的相关部分是:

[python]
recipe = zc.recipe.egg
interpreter = python
eggs = ${buildout:eggs}

如何让我的脚本使用 bin/python 而不是系统 python?

【问题讨论】:

    标签: python egg


    【解决方案1】:

    在您的 bash 脚本中,您依靠 $PATH 来确定要使用的 python。要更改调用哪个 python,您有多种选择:

    1. 修改您的环境以更喜欢不同的版本,即在 ~/.bashrc 中,添加 export PATH=/path/to/desired/python/bin:$PATH(当然还有适当的替换

    2. 修改 bash 脚本以显式声明 python 的路径,从而完全避免使用 $PATH

    3. 去掉python的显式调用,修改python脚本中的sha-bang选择合适的版本。 (另外,确保 python 脚本被标记为可执行)。

    【讨论】:

    • 我不想直接使用我系统中安装的任何其他版本的 Python。 buildout 创建了名为 myproject/bin/python 的脚本。这个脚本做的第一件事就是向路径中添加东西。我想继续使用那个设施。
    【解决方案2】:

    您需要将${buildout:executable} 的值替换到模板中。我不确定你是如何使用 buildout_script 配方来引用它的,也许是%(executable)s

    【讨论】:

    • 输出 /usr/bin/python :( :( :( :(
    猜你喜欢
    • 2023-03-12
    • 2017-07-21
    • 2020-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-15
    • 1970-01-01
    相关资源
    最近更新 更多