Pants pex 安装错误:"FAILURE: Unable to detect a suitable interpreter for compatibilities: (Conflicting targets: )"

Error from Pants pex install: "FAILURE: Unable to detect a suitable interpreter for compatibilities: (Conflicting targets: )"

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

我想使用捆绑了 Linux 和 MacOS 支持的 pex 发行版。 我正在使用 Pants OSS 存储库构建 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

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

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

中的库

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

好的 - 在版本 0.0.32 中查找失败消息我发现这个 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_interpretersinterpreter_cache 返回为空,并且该代码查看其键最近更改的配置值,以便 bootstrap 解释器。我猜您的存储库中有一个 pants.ini 配置缺少密钥名称更改。

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

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

我最近在升级 twitter/commons 时这样做了。更改已审核 here,工具输出如下所示:

$ ./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 密钥让您绊倒。