0

環境

  • Python3.7.7
  • pip 20.1.1

事前準備

vagrant@example:~$ docker run -it python:3.7.7 /bin/bash

root@df6e6126260a:/# pip --version
pip 20.1.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

root@df6e6126260a:/# pip list
Package    Version
---------- -------
pip        20.1.1
setuptools 47.1.1
wheel      0.34.2
WARNING: You are using pip version 20.1.1; however, version 22.1.2 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.

pip isntallで依存性競合のエラーが発生

poetry1.1.13をインストールすると、以下の依存性競合エラーが発生します。

root@df6e6126260a:/# pip install poetry==1.1.13
...
ERROR: keyring 23.6.0 has requirement importlib-metadata>=3.6; python_version < "3.10", but you'll have importlib-metadata 1.7.0 which is incompatible.
...
root@df6e6126260a:/# pip list
Package            Version
------------------ ---------
CacheControl       0.12.11
cachy              0.3.0
certifi            2022.6.15
cffi               1.15.1
charset-normalizer 2.1.0
cleo               0.8.1
clikit             0.6.2
crashtest          0.3.1
cryptography       37.0.4
distlib            0.3.4
filelock           3.7.1
html5lib           1.1
idna               3.3
importlib-metadata 1.7.0
jeepney            0.8.0
keyring            23.6.0
lockfile           0.12.2
msgpack            1.0.4
packaging          20.9
pastel             0.2.1
pexpect            4.8.0
pip                20.1.1
pkginfo            1.8.3
platformdirs       2.5.2
poetry             1.1.13
poetry-core        1.0.8
ptyprocess         0.7.0
pycparser          2.21
pylev              1.4.0
pyparsing          3.0.9
requests           2.28.1
requests-toolbelt  0.9.1
SecretStorage      3.3.2
setuptools         47.1.1
shellingham        1.4.0
six                1.16.0
tomlkit            0.11.1
urllib3            1.26.10
virtualenv         20.15.1
webencodings       0.5.1
wheel              0.34.2
zipp               3.8.0

質問

keyring22.3.0ならimportlib_metadata >= 1です。

https://github.com/jaraco/keyring/blob/e84f757f1aadfe779dbb8858e99de36c7283756f/setup.cfg#L28

したがって、先にkeyring22.3.0をインストールしてからpoetryをインストールすれば、エラーは発生しません。

# pip install keyring==22.3.0
# pip install poetry==1.1.13

なぜpipは、上記のように依存性を解決してくれないのでしょうか?
依存性を解決するアルゴリズムは難しいのでしょうか?

補足

TravisCI上でPython3.7で`poetry install`を実行すると、`importlib-metadata`のインストールで失敗します。 に関連した質問です。

pip installの標準出力すべて

# pip install poetry==1.1.13
Collecting poetry==1.1.13
  Downloading poetry-1.1.13-py2.py3-none-any.whl (175 kB)
     |████████████████████████████████| 175 kB 5.3 MB/s 
Collecting virtualenv<21.0.0,>=20.0.26
  Downloading virtualenv-20.15.1-py2.py3-none-any.whl (10.1 MB)
     |████████████████████████████████| 10.1 MB 11.1 MB/s 
Collecting requests-toolbelt<0.10.0,>=0.9.1
  Downloading requests_toolbelt-0.9.1-py2.py3-none-any.whl (54 kB)
     |████████████████████████████████| 54 kB 5.6 MB/s 
Collecting html5lib<2.0,>=1.0
  Downloading html5lib-1.1-py2.py3-none-any.whl (112 kB)
     |████████████████████████████████| 112 kB 13.7 MB/s 
Collecting packaging<21.0,>=20.4
  Downloading packaging-20.9-py2.py3-none-any.whl (40 kB)
     |████████████████████████████████| 40 kB 10.2 MB/s 
Collecting clikit<0.7.0,>=0.6.2
  Downloading clikit-0.6.2-py2.py3-none-any.whl (91 kB)
     |████████████████████████████████| 91 kB 10.5 MB/s 
Collecting cleo<0.9.0,>=0.8.1
  Downloading cleo-0.8.1-py2.py3-none-any.whl (21 kB)
Collecting importlib-metadata<2.0.0,>=1.6.0; python_version < "3.8"
  Downloading importlib_metadata-1.7.0-py2.py3-none-any.whl (31 kB)
Collecting tomlkit<1.0.0,>=0.7.0
  Downloading tomlkit-0.11.1-py3-none-any.whl (34 kB)
Collecting shellingham<2.0,>=1.1
  Downloading shellingham-1.4.0-py2.py3-none-any.whl (9.4 kB)
Collecting cachy<0.4.0,>=0.3.0
  Downloading cachy-0.3.0-py2.py3-none-any.whl (20 kB)
Collecting poetry-core<1.1.0,>=1.0.7
  Downloading poetry_core-1.0.8-py2.py3-none-any.whl (425 kB)
     |████████████████████████████████| 425 kB 33.3 MB/s 
Collecting requests<3.0,>=2.18
  Downloading requests-2.28.1-py3-none-any.whl (62 kB)
     |████████████████████████████████| 62 kB 2.7 MB/s 
Collecting cachecontrol[filecache]<0.13.0,>=0.12.9; python_version >= "3.6" and python_version < "4.0"
  Downloading CacheControl-0.12.11-py2.py3-none-any.whl (21 kB)
Collecting pexpect<5.0.0,>=4.7.0
  Downloading pexpect-4.8.0-py2.py3-none-any.whl (59 kB)
     |████████████████████████████████| 59 kB 9.3 MB/s 
Collecting crashtest<0.4.0,>=0.3.0; python_version >= "3.6" and python_version < "4.0"
  Downloading crashtest-0.3.1-py3-none-any.whl (7.0 kB)
Collecting keyring>=21.2.0; python_version >= "3.6" and python_version < "4.0"
  Downloading keyring-23.6.0-py3-none-any.whl (34 kB)
Collecting pkginfo<2.0,>=1.4
  Downloading pkginfo-1.8.3-py2.py3-none-any.whl (26 kB)
Collecting filelock<4,>=3.2
  Downloading filelock-3.7.1-py3-none-any.whl (10 kB)
Collecting six<2,>=1.9.0
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting distlib<1,>=0.3.1
  Downloading distlib-0.3.4-py2.py3-none-any.whl (461 kB)
     |████████████████████████████████| 461 kB 26.5 MB/s 
Collecting platformdirs<3,>=2
  Downloading platformdirs-2.5.2-py3-none-any.whl (14 kB)
Collecting webencodings
  Downloading webencodings-0.5.1-py2.py3-none-any.whl (11 kB)
Collecting pyparsing>=2.0.2
  Downloading pyparsing-3.0.9-py3-none-any.whl (98 kB)
     |████████████████████████████████| 98 kB 13.4 MB/s 
Collecting pastel<0.3.0,>=0.2.0
  Downloading pastel-0.2.1-py2.py3-none-any.whl (6.0 kB)
Collecting pylev<2.0,>=1.3
  Downloading pylev-1.4.0-py2.py3-none-any.whl (6.1 kB)
Collecting zipp>=0.5
  Downloading zipp-3.8.0-py3-none-any.whl (5.4 kB)
Collecting urllib3<1.27,>=1.21.1
  Downloading urllib3-1.26.10-py2.py3-none-any.whl (139 kB)
     |████████████████████████████████| 139 kB 29.9 MB/s 
Collecting certifi>=2017.4.17
  Downloading certifi-2022.6.15-py3-none-any.whl (160 kB)
     |████████████████████████████████| 160 kB 28.9 MB/s 
Collecting charset-normalizer<3,>=2
  Downloading charset_normalizer-2.1.0-py3-none-any.whl (39 kB)
Collecting idna<4,>=2.5
  Downloading idna-3.3-py3-none-any.whl (61 kB)
     |████████████████████████████████| 61 kB 9.3 MB/s 
Collecting msgpack>=0.5.2
  Downloading msgpack-1.0.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (299 kB)
     |████████████████████████████████| 299 kB 32.5 MB/s 
Collecting lockfile>=0.9; extra == "filecache"
  Downloading lockfile-0.12.2-py2.py3-none-any.whl (13 kB)
Collecting ptyprocess>=0.5
  Downloading ptyprocess-0.7.0-py2.py3-none-any.whl (13 kB)
Collecting jeepney>=0.4.2; sys_platform == "linux"
  Downloading jeepney-0.8.0-py3-none-any.whl (48 kB)
     |████████████████████████████████| 48 kB 5.7 MB/s 
Collecting SecretStorage>=3.2; sys_platform == "linux"
  Downloading SecretStorage-3.3.2-py3-none-any.whl (15 kB)
Collecting cryptography>=2.0
  Downloading cryptography-37.0.4-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.2 MB)
     |████████████████████████████████| 4.2 MB 23.1 MB/s 
Collecting cffi>=1.12
  Downloading cffi-1.15.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (427 kB)
     |████████████████████████████████| 427 kB 24.5 MB/s 
Collecting pycparser
  Downloading pycparser-2.21-py2.py3-none-any.whl (118 kB)
     |████████████████████████████████| 118 kB 16.2 MB/s 
ERROR: keyring 23.6.0 has requirement importlib-metadata>=3.6; python_version < "3.10", but you'll have importlib-metadata 1.7.0 which is incompatible.
Installing collected packages: filelock, six, distlib, platformdirs, zipp, importlib-metadata, virtualenv, urllib3, certifi, charset-normalizer, idna, requests, requests-toolbelt, webencodings, html5lib, pyparsing, packaging, pastel, crashtest, pylev, clikit, cleo, tomlkit, shellingham, cachy, poetry-core, msgpack, lockfile, cachecontrol, ptyprocess, pexpect, jeepney, pycparser, cffi, cryptography, SecretStorage, keyring, pkginfo, poetry
Successfully installed SecretStorage-3.3.2 cachecontrol-0.12.11 cachy-0.3.0 certifi-2022.6.15 cffi-1.15.1 charset-normalizer-2.1.0 cleo-0.8.1 clikit-0.6.2 crashtest-0.3.1 cryptography-37.0.4 distlib-0.3.4 filelock-3.7.1 html5lib-1.1 idna-3.3 importlib-metadata-1.7.0 jeepney-0.8.0 keyring-23.6.0 lockfile-0.12.2 msgpack-1.0.4 packaging-20.9 pastel-0.2.1 pexpect-4.8.0 pkginfo-1.8.3 platformdirs-2.5.2 poetry-1.1.13 poetry-core-1.0.8 ptyprocess-0.7.0 pycparser-2.21 pylev-1.4.0 pyparsing-3.0.9 requests-2.28.1 requests-toolbelt-0.9.1 shellingham-1.4.0 six-1.16.0 tomlkit-0.11.1 urllib3-1.26.10 virtualenv-20.15.1 webencodings-0.5.1 zipp-3.8.0
WARNING: You are using pip version 20.1.1; however, version 22.1.2 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.

1 件の回答 1

0

pip 20.1.1があまり賢くなかったようです。
pip 22.1.2でpoetryをインストールしたら、エラーは発生しませんでした。

# pip install poetry==1.1.13
Collecting poetry==1.1.13
  Downloading poetry-1.1.13-py2.py3-none-any.whl (175 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 175.1/175.1 kB 6.7 MB/s eta 0:00:00
Collecting cachecontrol[filecache]<0.13.0,>=0.12.9
  Downloading CacheControl-0.12.11-py2.py3-none-any.whl (21 kB)
Collecting pkginfo<2.0,>=1.4
  Downloading pkginfo-1.8.3-py2.py3-none-any.whl (26 kB)
Collecting cleo<0.9.0,>=0.8.1
  Downloading cleo-0.8.1-py2.py3-none-any.whl (21 kB)
Collecting cachy<0.4.0,>=0.3.0
  Downloading cachy-0.3.0-py2.py3-none-any.whl (20 kB)
Collecting shellingham<2.0,>=1.1
  Downloading shellingham-1.4.0-py2.py3-none-any.whl (9.4 kB)
Collecting importlib-metadata<2.0.0,>=1.6.0
  Downloading importlib_metadata-1.7.0-py2.py3-none-any.whl (31 kB)
Collecting html5lib<2.0,>=1.0
  Downloading html5lib-1.1-py2.py3-none-any.whl (112 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 112.2/112.2 kB 24.6 MB/s eta 0:00:00
Collecting crashtest<0.4.0,>=0.3.0
  Downloading crashtest-0.3.1-py3-none-any.whl (7.0 kB)
Collecting virtualenv<21.0.0,>=20.0.26
  Downloading virtualenv-20.15.1-py2.py3-none-any.whl (10.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 10.1/10.1 MB 17.6 MB/s eta 0:00:00
Collecting requests<3.0,>=2.18
  Downloading requests-2.28.1-py3-none-any.whl (62 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.8/62.8 kB 15.7 MB/s eta 0:00:00
Collecting pexpect<5.0.0,>=4.7.0
  Downloading pexpect-4.8.0-py2.py3-none-any.whl (59 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 59.0/59.0 kB 15.1 MB/s eta 0:00:00
Collecting tomlkit<1.0.0,>=0.7.0
  Downloading tomlkit-0.11.1-py3-none-any.whl (34 kB)
Collecting keyring>=21.2.0
  Downloading keyring-23.6.0-py3-none-any.whl (34 kB)
Collecting requests-toolbelt<0.10.0,>=0.9.1
  Downloading requests_toolbelt-0.9.1-py2.py3-none-any.whl (54 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 54.3/54.3 kB 11.6 MB/s eta 0:00:00
Collecting packaging<21.0,>=20.4
  Downloading packaging-20.9-py2.py3-none-any.whl (40 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 40.9/40.9 kB 8.4 MB/s eta 0:00:00
Collecting poetry-core<1.1.0,>=1.0.7
  Downloading poetry_core-1.0.8-py2.py3-none-any.whl (425 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 425.0/425.0 kB 27.5 MB/s eta 0:00:00
Collecting clikit<0.7.0,>=0.6.2
  Downloading clikit-0.6.2-py2.py3-none-any.whl (91 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 91.8/91.8 kB 26.4 MB/s eta 0:00:00
Collecting msgpack>=0.5.2
  Downloading msgpack-1.0.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (299 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 299.8/299.8 kB 39.6 MB/s eta 0:00:00
Collecting lockfile>=0.9
  Downloading lockfile-0.12.2-py2.py3-none-any.whl (13 kB)
Collecting pastel<0.3.0,>=0.2.0
  Downloading pastel-0.2.1-py2.py3-none-any.whl (6.0 kB)
Collecting pylev<2.0,>=1.3
  Downloading pylev-1.4.0-py2.py3-none-any.whl (6.1 kB)
Collecting six>=1.9
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting webencodings
  Downloading webencodings-0.5.1-py2.py3-none-any.whl (11 kB)
Collecting zipp>=0.5
  Downloading zipp-3.8.0-py3-none-any.whl (5.4 kB)
Collecting jeepney>=0.4.2
  Downloading jeepney-0.8.0-py3-none-any.whl (48 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 48.4/48.4 kB 14.3 MB/s eta 0:00:00
Collecting keyring>=21.2.0
  Downloading keyring-23.5.1-py3-none-any.whl (33 kB)
  Downloading keyring-23.5.0-py3-none-any.whl (33 kB)
  Downloading keyring-23.4.1-py3-none-any.whl (33 kB)
  Downloading keyring-23.4.0-py3-none-any.whl (33 kB)
  Downloading keyring-23.3.0-py3-none-any.whl (33 kB)
  Downloading keyring-23.2.1-py3-none-any.whl (33 kB)
  Downloading keyring-23.2.0-py3-none-any.whl (33 kB)
  Downloading keyring-23.1.0-py3-none-any.whl (32 kB)
  Downloading keyring-23.0.1-py3-none-any.whl (33 kB)
  Downloading keyring-23.0.0-py3-none-any.whl (32 kB)
  Downloading keyring-22.4.0-py3-none-any.whl (58 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 58.5/58.5 kB 9.7 MB/s eta 0:00:00
  Downloading keyring-22.3.0-py3-none-any.whl (58 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 58.6/58.6 kB 13.8 MB/s eta 0:00:00
Collecting SecretStorage>=3.2
  Downloading SecretStorage-3.3.2-py3-none-any.whl (15 kB)
Collecting pyparsing>=2.0.2
  Downloading pyparsing-3.0.9-py3-none-any.whl (98 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 98.3/98.3 kB 18.8 MB/s eta 0:00:00
Collecting ptyprocess>=0.5
  Downloading ptyprocess-0.7.0-py2.py3-none-any.whl (13 kB)
Collecting idna<4,>=2.5
  Downloading idna-3.3-py3-none-any.whl (61 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.2/61.2 kB 17.3 MB/s eta 0:00:00
Collecting charset-normalizer<3,>=2
  Downloading charset_normalizer-2.1.0-py3-none-any.whl (39 kB)
Collecting urllib3<1.27,>=1.21.1
  Downloading urllib3-1.26.10-py2.py3-none-any.whl (139 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 139.2/139.2 kB 25.7 MB/s eta 0:00:00
Collecting certifi>=2017.4.17
  Downloading certifi-2022.6.15-py3-none-any.whl (160 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 160.2/160.2 kB 16.7 MB/s eta 0:00:00
Collecting filelock<4,>=3.2
  Downloading filelock-3.7.1-py3-none-any.whl (10 kB)
Collecting platformdirs<3,>=2
  Downloading platformdirs-2.5.2-py3-none-any.whl (14 kB)
Collecting distlib<1,>=0.3.1
  Downloading distlib-0.3.4-py2.py3-none-any.whl (461 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 461.2/461.2 kB 18.8 MB/s eta 0:00:00
Collecting cryptography>=2.0
  Downloading cryptography-37.0.4-cp36-abi3-manylinux_2_24_x86_64.whl (4.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.1/4.1 MB 16.2 MB/s eta 0:00:00
Collecting cffi>=1.12
  Downloading cffi-1.15.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (427 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 427.9/427.9 kB 36.7 MB/s eta 0:00:00
Collecting pycparser
  Downloading pycparser-2.21-py2.py3-none-any.whl (118 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 118.7/118.7 kB 20.7 MB/s eta 0:00:00
Installing collected packages: webencodings, pylev, ptyprocess, msgpack, lockfile, distlib, zipp, urllib3, tomlkit, six, shellingham, pyparsing, pycparser, platformdirs, pkginfo, pexpect, pastel, jeepney, idna, filelock, crashtest, charset-normalizer, certifi, cachy, requests, packaging, importlib-metadata, html5lib, clikit, cffi, virtualenv, requests-toolbelt, poetry-core, cryptography, cleo, cachecontrol, SecretStorage, keyring, poetry
Successfully installed SecretStorage-3.3.2 cachecontrol-0.12.11 cachy-0.3.0 certifi-2022.6.15 cffi-1.15.1 charset-normalizer-2.1.0 cleo-0.8.1 clikit-0.6.2 crashtest-0.3.1 cryptography-37.0.4 distlib-0.3.4 filelock-3.7.1 html5lib-1.1 idna-3.3 importlib-metadata-1.7.0 jeepney-0.8.0 keyring-22.3.0 lockfile-0.12.2 msgpack-1.0.4 packaging-20.9 pastel-0.2.1 pexpect-4.8.0 pkginfo-1.8.3 platformdirs-2.5.2 poetry-1.1.13 poetry-core-1.0.8 ptyprocess-0.7.0 pycparser-2.21 pylev-1.4.0 pyparsing-3.0.9 requests-2.28.1 requests-toolbelt-0.9.1 shellingham-1.4.0 six-1.16.0 tomlkit-0.11.1 urllib3-1.26.10 virtualenv-20.15.1 webencodings-0.5.1 zipp-3.8.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

問題となるkeyringですが、最初は最新であるkeyring23.6.0をダウンロードしていました。その後、keyringのバージョンを一つずつダウングレードしながらダウンロードしていました。バージョンごとに依存性の制約を満たしているか確認しているようです。

pip20.1.1よりpip22.1.2の方が依存性を解決してくれることが分かりました。

pip20.3から依存性解決が賢くなったようですね。
https://www.python.jp/pages/2020-10-07-new-pip-deps.html

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。