【问题标题】:There are incompatible versions in the resolved dependencies已解决的依赖项中有不兼容的版本
【发布时间】:2021-08-11 14:14:20
【问题描述】:

我正在尝试运行我的 python 项目,该项目似乎在我的 Mac 上运行良好(最好在 pycharm 中,不太好但可以在 VSCode 中运行),但在我的 VSCode 中的树莓派上却很糟糕。每当我运行 pipenv shell 然后运行 ​​pipenv install 时,它只会抱怨这个错误:

Pipfile.lock (e9a11d) out of date, updating to (47943b)...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Building requirements...
Resolving dependencies...
✘ Locking Failed! 
[ResolutionFailure]:   File "/home/nick/.local/lib/python3.7/site-packages/pipenv/resolver.py", line 741, in _main
[ResolutionFailure]:       resolve_packages(pre, clear, verbose, system, write, requirements_dir, packages, dev)
[ResolutionFailure]:   File "/home/nick/.local/lib/python3.7/site-packages/pipenv/resolver.py", line 709, in resolve_packages
[ResolutionFailure]:       requirements_dir=requirements_dir,
[ResolutionFailure]:   File "/home/nick/.local/lib/python3.7/site-packages/pipenv/resolver.py", line 692, in resolve
[ResolutionFailure]:       req_dir=requirements_dir
[ResolutionFailure]:   File "/home/nick/.local/lib/python3.7/site-packages/pipenv/utils.py", line 1403, in resolve_deps
[ResolutionFailure]:       req_dir=req_dir,
[ResolutionFailure]:   File "/home/nick/.local/lib/python3.7/site-packages/pipenv/utils.py", line 1108, in actually_resolve_deps
[ResolutionFailure]:       resolver.resolve()
[ResolutionFailure]:   File "/home/nick/.local/lib/python3.7/site-packages/pipenv/utils.py", line 833, in resolve
[ResolutionFailure]:       raise ResolutionFailure(message=str(e))
[pipenv.exceptions.ResolutionFailure]: Warning: Your dependencies could not be resolved. You likely have a mismatch in your sub-dependencies.
  First try clearing your dependency cache with $ pipenv lock --clear, then try the original command again.
 Alternatively, you can use $ pipenv install --skip-lock to bypass this mechanism, then run $ pipenv graph to inspect the situation.
  Hint: try $ pipenv lock --pre if it is a pre-release dependency.
ERROR: Could not find a version that matches graphene-django>=3.0.0b1 (from -r /tmp/pipenvcczdc6ayrequirements/pipenv-eg1jqra7-constraints.txt (line 3))
Tried: 1.0, 1.1.0, 1.2.0, 1.2.1, 1.3, 2.0.0, 2.0.0, 2.1.0, 2.1.0, 2.2.0, 2.2.0, 2.3.0, 2.3.0, 2.3.2, 2.3.2, 2.4.0, 2.4.0, 2.5.0, 2.5.0, 2.6.0, 2.6.0, 2.7.0, 2.7.0, 2.7.1, 2.7.1, 2.8.0, 2.8.0, 2.8.1, 2.8.1, 2.8.2, 2.8.2, 2.9.0, 2.9.0, 2.9.1, 2.9.1, 2.10.0, 2.10.0, 2.10.1, 2.10.1, 2.11.0, 2.11.0, 2.11.1, 2.11.1, 2.12.0, 2.12.0, 2.12.1, 2.12.1, 2.13.0, 2.13.0, 2.14.0, 2.14.0, 2.15.0, 2.15.0
Skipped pre-versions: 1.0.dev20160909000001, 1.0.dev20160910000001, 1.0.dev20160917000001, 1.0.dev20160919000001, 1.0.dev20160919000002, 1.0.dev20160919000003, 1.0.dev20160919000004, 1.0.dev20160920000001, 1.0.dev20160922000001, 2.0.dev2017072501, 2.0.dev2017072601, 2.0.dev2017073101, 2.0.dev2017073101, 2.0.dev2017083101, 2.0.dev2017083101, 2.1rc0, 2.1rc0, 2.1rc1, 2.1rc1, 3.0.0b1, 3.0.0b1, 3.0.0b2, 3.0.0b2, 3.0.0b3, 3.0.0b3, 3.0.0b4, 3.0.0b4, 3.0.0b5, 3.0.0b5, 3.0.0b6, 3.0.0b6, 3.0.0b7, 3.0.0b7
There are incompatible versions in the resolved dependencies:
  graphene-django (from -r /tmp/pipenvcczdc6ayrequirements/pipenv-eg1jqra7-constraints.txt (line 3))
  graphene-django>=3.0.0b1 (from django-graphql-jwt==0.3.2->-r /tmp/pipenvcczdc6ayrequirements/pipenv-eg1jqra7-constraints.txt (line 5))

在运行 pipenv graphpipenv install --skip-lock 之后)后,我看不出有什么不兼容的地方,因为它返回:

django-cors-headers==3.7.0
  - Django [required: >=2.2, installed: 3.2.3]
    - asgiref [required: >=3.3.2,<4, installed: 3.3.4]
      - typing-extensions [required: Any, installed: 3.10.0.0]
    - pytz [required: Any, installed: 2021.1]
    - sqlparse [required: >=0.2.2, installed: 0.4.1]
django-graphql-jwt==0.3.2
  - Django [required: >=1.11, installed: 3.2.3]
    - asgiref [required: >=3.3.2,<4, installed: 3.3.4]
      - typing-extensions [required: Any, installed: 3.10.0.0]
    - pytz [required: Any, installed: 2021.1]
    - sqlparse [required: >=0.2.2, installed: 0.4.1]
  - graphene-django [required: >=3.0.0b1, installed: 3.0.0b7]
    - Django [required: >=2.2, installed: 3.2.3]
      - asgiref [required: >=3.3.2,<4, installed: 3.3.4]
        - typing-extensions [required: Any, installed: 3.10.0.0]
      - pytz [required: Any, installed: 2021.1]
      - sqlparse [required: >=0.2.2, installed: 0.4.1]
    - graphene [required: >=3.0.0b5,<4, installed: 3.0b7]
      - aniso8601 [required: >=8,<9, installed: 8.1.1]
      - graphql-core [required: >=3.1.2,<4, installed: 3.1.5]
      - graphql-relay [required: >=3.0,<4, installed: 3.1.0]
        - graphql-core [required: >=3.1, installed: 3.1.5]
        - typing-extensions [required: >=3.7,<4, installed: 3.10.0.0]
    - graphql-core [required: >=3.1.0,<4, installed: 3.1.5]
    - promise [required: >=2.1, installed: 2.3]
      - six [required: Any, installed: 1.16.0]
    - text-unidecode [required: Any, installed: 1.3]
  - PyJWT [required: >=2,<3, installed: 2.1.0]
Rx==1.6.1
singledispatch==3.6.1
  - six [required: Any, installed: 1.16.0]

似乎每个版本都在版本范围内正确安装,包括它抱怨的 graphene-django [required: >=3.0.0b1, installed: 3.0.0b7]。

为什么会出现这个错误?

pip3 list 返回:

Package             Version
------------------- --------
aniso8601           8.1.1
asgiref             3.3.4
Django              3.2.3
django-cors-headers 3.7.0
django-graphql-jwt  0.3.2
graphene            3.0b7
graphene-django     3.0.0b7
graphql-core        3.1.5
graphql-relay       3.1.0
pip                 21.1.1
promise             2.3
PyJWT               2.1.0
pytz                2021.1
Rx                  1.6.1
setuptools          56.0.0
singledispatch      3.6.1
six                 1.16.0
sqlparse            0.4.1
text-unidecode      1.3
typing-extensions   3.10.0.0
wheel               0.36.2

Pipfile:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
django = "*"
django-graphql-jwt = "*"
pyjwt = "1.7.1"
django-cors-headers = "*"
graphene-django = "*"

[requires]
python_version = "3.7"

[dev-packages]

我已经尝试了很多方法来解决这个问题,任何人都不知道从哪里开始。我想在我的树莓派上部署这个 python、graphql 和 react 项目,但如果我什至不能让它运行,我想我不能。我正在尝试在我的树莓派(运行 raspbian)上运行它,它是问题所在的后端 python 应用程序。

任何帮助,任何事情都会非常感激。我是python的初学者。

【问题讨论】:

  • 如果我从我的 Pipfile 中删除 django-graphql-jwt = "*" 然后 pipenv installpython manage.py runserver 运行成功,但是我得到这个错误,所以肯定需要那个模块:Could not import 'app.schema.schema' for Graphene setting 'SCHEMA'. ModuleNotFoundError: No module named 'graphql_jwt'. - 我认为错误表明问题出在 graphene-django,而不是 django-graphql-jwt

标签: python django pip pipenv pipenv-install


【解决方案1】:

您以某种方式设法安装了 beta 版本(例如,之前使用了 --pre 标志,然后从 Pipfile 中删除了该选项,或者直接在虚拟环境中使用了 pip)。

现在,因为django-graphql-jwt 不符合语义版本控制,他们决定依赖主要版本,在补丁版本¯\_(ツ)_/¯ 中预发布 .

由于 django-graphql-jtw 的 0.3.1 版本依赖于 &gt;=2.5.1,您的 beta 版本仍将匹配,但没有 --pre 标志锁定将失败,因为最高的非 beta 版本是 2.5.1。这就是显示的冲突(但输出不是很清楚)。

应该解决问题的解决方案是:

pipenv uninstall django-graphql-jwt django-graphene graphene graphql
# followed by:
pipenv install 'django-graphql-jwt<0.3.2'

【讨论】:

  • 成功了!谢谢你,做得好!你怎么知道 django-graphql-jwt 依赖于一个主要版本(>=2.5.1)? --pre 标志是什么?
  • 谢谢你,Melvyn,这不仅是解决一个非常令人沮丧的问题的好方法,也是一个很好的解释。
【解决方案2】:

根据 PyPI https://pypi.org/project/graphene-django/,问题似乎是 graphene-django 只有版本 2.15.0。但出于某种原因,在图书馆django-graphql-jwt 的这个commit 中,它要求 一个版本3.0.0b1。我认为这是您的日志中显示的问题:

ERROR: Could not find a version that matches graphene-django>=3.0.0b1 (from -r /tmp/pipenvcczdc6ayrequirements/pipenv-eg1jqra7-constraints.txt (line 3))

显然,在这个commit 中,最新的graphene-django 版本仍受支持。所以我的猜测是可能降级为:

django-graphql-jwt="0.3.1"

而不是0.3.2 应该可以解决问题。在这种情况下,您可以向他们报告问题。

【讨论】:

  • 恐怕还是和以前一样的错误
【解决方案3】:

实际上 Pipenv 没有足够聪明的依赖解析器。我遇到了类似的问题并切换到poetry。 Poetry 会将您的依赖关系解析为符合约束且不相互冲突的最新版本。 Poetry 也比 Pipenv 快得多,并提供更好的用户体验。

# pyproject.toml

[build-system]
requires = ["poetry>=1.12"]
build-backend = "poetry.masonry.api"

[tool.poetry]
name = "sample"
version = "0.1.0"
description = "Sample"
authors = []

[tool.poetry.dependencies]
python = "~3.7"

django = "*"
django-graphql-jwt = "*"
pyjwt = "1.7.1"
django-cors-headers = "*"
graphene-django = "*"

在外壳中:

$ poetry --version
Poetry version 1.1.6

$ poetry lock
Updating dependencies
Resolving dependencies... (15.3s)

Writing lock file

$ poetry install
Installing dependencies from lock file

Package operations: 17 installs, 0 updates, 0 removals

  • Installing six (1.16.0)
  • Installing promise (2.3)
  • Installing rx (1.6.1)
  • Installing graphql-core (2.3.2)
  • Installing typing-extensions (3.10.0.0)
  • Installing aniso8601 (7.0.0)
  • Installing asgiref (3.3.4)
  • Installing graphql-relay (2.0.1)
  • Installing pytz (2021.1)
  • Installing django (3.2.3)
  • Installing graphene (2.1.8)
  • Installing singledispatch (3.6.2)
  • Installing text-unidecode (1.3)
  • Installing graphene-django (2.15.0)
  • Installing pyjwt (1.7.1)
  • Installing django-cors-headers (3.7.0)
  • Installing django-graphql-jwt (0.3.1)

【讨论】:

  • 看起来很有趣,虽然安装失败:运行命令 curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python - 遇到此语法错误:` 文件 "",第 134 行 def data_dir(version: Optional[str] = None) - > 路径:^ SyntaxError: invalid syntax curl: (23) Failed writing body (363 != 1369)`
  • 您可能正在使用python 2。我记得,诗歌至少需要python 3.6。尝试相同的命令,但改用python3
  • 安装成功,但仍然无法解决依赖问题
  • @user8758206,你用的是什么版本的诗?刚刚检查过,它对我有用(更新了答案,请在此处查看确切版本)
  • 我确实运行了它,但是立即使用 --pre 并没有解决它,因为上游的 deps 被破坏了。我说这是已安装软件包中出现 beta 版本的一个可能原因。是的,诗歌确实为您提供了一个有效的环境,如果这对您来说没问题,那就去吧。它没有按照您的要求进行(安装最新发布的 django-graphql-jwt 版本),并且经常让我感到厌烦,以至于我远离它。但是很难写出一个好的包管理器,尤其是对于“正确”的不同哲学。
猜你喜欢
  • 2012-12-16
  • 1970-01-01
  • 2023-03-08
  • 1970-01-01
  • 1970-01-01
  • 2023-03-05
  • 1970-01-01
  • 2013-01-24
  • 2020-04-17
相关资源
最近更新 更多