简体   繁体   English

zc.buildout使用错误的python

[英]zc.buildout is using the wrong python

I'm using zc.buildout to generate a script called "test". 我正在使用zc.buildout生成一个名为“ test”的脚本。 I'm using that script to call my own test runner. 我正在使用该脚本来调用我自己的测试运行程序。 (The available test runners for buildout do not yet use the new "discovery" feature in Python 2.7.) (用于扩展的可用测试运行程序尚未使用Python 2.7中的新“发现”功能。)

Anyhow, here's the relevant section in my .cfg file: 无论如何,这是我的.cfg文件中的相关部分:

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

Here is what my runtests.sh.in template looks like 这是我的runtests.sh.in模板的样子

#!/bin/bash

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

And here is the resulting output that is placed in my bin folder as bin/test . 这是结果输出,作为bin/test放在我的bin文件夹中。

!/bin/bash

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

When I execute this script, it's using the system Python instead of the Python in my bin folder. 执行此脚本时,它使用的是系统Python,而不是bin文件夹中的Python。

The relevant section for that in my .cfg file is: 我的.cfg文件中与此相关的部分是:

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

How do I get my script to use bin/python instead of the system python? 如何获取脚本以使用bin / python而不是系统python?

In your bash script, your are relying upon $PATH to determine which python to use. 在您的bash脚本中,您依靠$PATH确定要使用哪个python。 To change which python is invoked, you have several choices: 要更改调用哪个python,您有几种选择:

  1. Modify your environment to prefer a different version, ie in ~/.bashrc, add export PATH=/path/to/desired/python/bin:$PATH (of course with the appropriate substitutions 修改您的环境以使用其他版本,例如,在〜/ .bashrc中,添加export PATH=/path/to/desired/python/bin:$PATH (当然,使用适当的替代方法

  2. Modify your bash script to explicitly state the path to python, thus avoiding using $PATH at all. 修改bash脚本以显式声明python的路径,从而完全避免使用$PATH

  3. Remove the explicit invocation of python, and change the sha-bang in the python script to select the appropriate version. 删除python的显式调用,并更改python脚本中的sha-bang以选择适当的版本。 (also, make sure the python script is marked executable). (还要确保python脚本被标记为可执行)。

You need to substitute the value of ${buildout:executable} into the template. 您需要将${buildout:executable}的值替换为模板。 I'm not sure how you refer to that using the buildout_script recipe, perhaps %(executable)s ? 我不确定您如何使用buildout_script配方(也许是%(executable)s来引用它?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM