

# 環境

  * Ubuntu 20.04
  * Python3.7.7
  * pip 20.1
  * poetry 1.1.13

# やりたいこと

TravisCI上で、Python3.7から3.10のテストを実施したいです。

# 問題

Python3.7の環境では、`poetry install`で以下のエラーが発生しました。

[code]

    16.45s$ travis_retry poetry install
    Installing dependencies from lock file
    Package operations: 60 installs, 10 updates, 0 removals
      • Installing typing-extensions (4.2.0): Pending...
      • Updating zipp (3.1.0 -> 3.8.0): Pending...
    • Updating zipp (3.1.0 -> 3.8.0): Pending...
    • Installing typing-extensions (4.2.0): Failed
      • Updating zipp (3.1.0 -> 3.8.0): Pending...
      • Updating zipp (3.1.0 -> 3.8.0): Pending...
    EnvCommandError
      • Updating zipp (3.1.0 -> 3.8.0): Pending...
      • Updating zipp (3.1.0 -> 3.8.0): Pending...
    Command ['/home/travis/virtualenv/python3.7.7/bin/python', '-W', 'ignore', '-'] errored with the following return code 1, and output: 
      Traceback (most recent call last):
        File "<stdin>", line 871, in <module>
        File "<stdin>", line 871, in <listcomp>
        File "<stdin>", line 860, in sys_tags
        File "<stdin>", line 277, in cpython_tags
        File "<stdin>", line 785, in _linux_platforms
      AttributeError: module 'distutils' has no attribute 'util'
      input was : # This file is dual licensed under the terms of the Apache License, Version
      # 2.0, and the BSD License. See the LICENSE file in the root of this repository
      # for complete details.
      
      from __future__ import absolute_import
      
      import distutils.util
    
[/code]

<https://app.travis-ci.com/github/kurusugawa-computer/annofab-api-python-
client/jobs/575582381#L292-L320>

# 質問

このエラーは何を意味していて、どのように解決すればよいでしょうか？

# 補足

## pip install poetryでエラー発生

`pip install poetry`コマンドで、以下のエラーが発生していました。これが関係しているのかもしれません。

[code]

    $ pip install poetry
    ...
    
    Collecting pycparser
      Using cached pycparser-2.21-py2.py3-none-any.whl (118 kB)
    ERROR: keyring 23.6.0 has requirement importlib-metadata>=3.6; python_version < "3.10", but you'll have importlib-metadata 1.6.0 which is incompatible.
    ERROR: poetry-core 1.0.8 has requirement importlib-metadata<2.0.0,>=1.7.0; python_version >= "2.7" and python_version < "2.8" or python_version >= "3.5" and python_version < "3.8", but you'll have importlib-metadata 1.6.0 which is incompatible.
    
[/code]

<https://app.travis-ci.com/github/kurusugawa-computer/annofab-api-python-
client/jobs/575582381#L274-L278>

追記：keyring22.3.0を先にインストールすれば、このエラーは発生しなくなることは確認しました。  
[Python3.7で"pip install poetry"を実行すると、"importlib-
metadata"で依存性競合のエラーが発生します。なぜ、pipは依存性をうまい具合に解決してくれないのでしょうか？](https://ja.stackoverflow.com/questions/89904/)

## ローカル環境では成功する

ローカル環境でPython3.7.7を作成して`poetry install`を実行したら、エラーは発生しませんでした。

[code]

    $ python --version
    Python 3.7.7
    
    $ pip --version
    pip 19.2.3 from /home/vagrant/.pyenv/versions/3.7.7/lib/python3.7/site-packages/pip (python 3.7)
    
    $ poetry --version
    Poetry version 1.1.13
    
    
[/code]

## 以前のビルド結果

以前はPython3.7で`poetry install`が成功していました。  
<https://app.travis-ci.com/github/kurusugawa-computer/annofab-api-python-
client/jobs/572311461>

## travis.yaml

[code]

    version: ~> 1.0
    dist: focal
    language: python
    python:
      - "3.7"
      - "3.8"
      - "3.9"
      - "3.10"
    install:
      - pip install poetry
      - travis_retry poetry install
    env:
      - PIP_DEFAULT_TIMEOUT=100
    
    cache: pip
    
[/code]

## pyproject.toml

[code]

    [tool.poetry.dependencies]
    python = "^3.7"
    requests = "*"
    python-dateutil = "*"
    backoff="*"
    dataclasses-json="*"
    more-itertools = "*"
    
    
    [tool.poetry.dev-dependencies]
    pytest = "*"
    pytest-xdist = "*"
    pytest-cov = "*"
    isort = "*"
    autoflake = "*"
    black = "*"
    flake8 = "*"
    mypy = "*"
    pylint = "*"
    sphinx = "*"
    docutils = "*"
    pydata-sphinx-theme = "*"
    types-requests = "*"
    types-python-dateutil = "*"
    types-dataclasses = { version = "*", python = "<3.7" }
    ipython = "*"
    jedi = "<0.18"
    
[/code]


CC BY-SA 4.0
2022-07-05T14:32:27.150
89772
2022-07-11T02:41:18.947
2022-07-11T02:41:18.947
19524
19524
question
python travis-ci poetry
TravisCI上でPython3.7で`poetry install`を実行すると、`importlib-metadata`のインストールで失敗します。