1

我正在使用裤子版本 0.0.32 + 来自 master 的更多提交。

我想使用捆绑了 Linux 和 MacOS 支持的 pex 发行版。我正在使用 Pants OSS repo 构建 pex:

git clean -fdx
PANTS_DEV=1 ./pants binary ./src/python/pants/bin:pants

我使用了新创建的文件 dist/pants.pex,它在我的 Mac 上运行良好。当我尝试在我的 Linux 环境中运行它时,它退出并出现错误:

./pants test foo
Running Pants version square-20150331-02
...
11:53:22 00:08     [pytest]
11:53:22 00:08       [run]
                 WARN] /data/app/kochiku-worker/.pex/install/requests-2.5.3-py2.py3-none-any.whl.ed9d28acc3c467062b25b9dc2e2084d6efa8ee1e/requests-2.5.3-py2.py3-none-any.whl/requests/packages/urllib3/connection.py:251: SecurityWarning: Certificate has no `subjectAltName`, falling back to check for a `commonName` for now. This feature is being removed by major browsers and deprecated by RFC 2818. (See https://github.com/shazow/urllib3/issues/497 for details.)
  SecurityWarning


FAILURE: Unable to detect a suitable interpreter for compatibilities:  (Conflicting targets: )

[32m
           Waiting for background workers to finish.[0m[31m
           FAILURE[0m

我认为这里发生的事情是,出于某种原因,裤子在 Python 2.6 下运行。我调查了安全错误,似乎在使用早于 python 2.7.2 的 python 版本时可能会意外触发它。我尝试使用的机器上安装的 python 版本安装在 /usr/local/bin 中,版本为 2.7.9

4

2 回答 2

3

好的 - 在 0.0.32 版本中寻找 FAILURE 消息我找到了这个python_task.py代码:

def select_interpreter_for_targets(self, targets):
  """Pick an interpreter compatible with all the specified targets."""
  allowed_interpreters = OrderedSet(self.interpreter_cache.interpreters)
  targets_with_compatibilities = []  # Used only for error messages.

  # Constrain allowed_interpreters based on each target's compatibility requirements.
  for target in targets:
    if target.is_python and hasattr(target, 'compatibility') and target.compatibility:
      targets_with_compatibilities.append(target)
      compatible_with_target = list(self.interpreter_cache.matches(target.compatibility))
      allowed_interpreters &= compatible_with_target

  if not allowed_interpreters:
    # Create a helpful error message.
    unique_compatibilities = set(tuple(t.compatibility) for t in targets_with_compatibilities)
    unique_compatibilities_strs = [','.join(x) for x in unique_compatibilities if x]
    targets_with_compatibilities_strs = [str(t) for t in targets_with_compatibilities]
    raise TaskError('Unable to detect a suitable interpreter for compatibilities: %s '
                    '(Conflicting targets: %s)' % (' && '.join(unique_compatibilities_strs),
                                                   ', '.join(targets_with_compatibilities_strs)))

allowed_interpreters中返回为空,interpreter_cache该代码查看其键最近更改的配置值,以引导解释器。我猜您的pants.ini存储库中有一个缺少键名更改的配置。

pants.ini在pantsbuild repo 中有一个工具可以检查过时的配置键。您可以从指向您自己的存储库的pantsbuild/pants 存储库的克隆中运行它,pants.ini如下所示:

$ ./pants run src/python/pants/option/:migrate_config -- [path to your repo's pants.ini]

我最近在升级 twitter/commons 时这样做了。此处查看了更改,工具输出如下所示:

$ ./pants run src/python/pants/option/:migrate_config -- ~/dev-jsirois-commons/pants.ini
...
17:53:44 00:00   [run]
17:53:44 00:00     [py]
17:53:44 00:00       [chroot]
17:53:44 00:00       [run]
Checking config file at /home/jsirois/dev-jsirois-commons/pants.ini for unmigrated keys.
Found indices in section [python-repos]. Should be indexes in section [python-repos].

17:53:44 00:00     [jvm]
17:53:44 00:00     [cpp-run]
               SUCCESS

注意Found indices in section [python-repos]. Should be indexes in section [python-repos]. 您可能也有同样的未迁移inidices密钥使您绊倒。

于 2015-04-03T00:01:56.883 回答
1

您可以使用环境变量 PEX_VERBOSE=1 运行——这将为您提供有关正在运行的 Python 版本的更多信息。您的系统 Python 也可能以某种方式错误配置为使用 2.6 中的库。

作为核选项,您可以尝试https://github.com/wickman/python-bootstrap/blob/master/bootstrap_python.sh看看这是否有助于修复您的 python 环境。

于 2015-04-02T23:40:19.807 回答