繁体   English   中英

如何用pipenv解决Python package依赖?

[英]How to resolve Python package dependencies with pipenv?

我正在使用pipenv来处理 Python package 依赖项。

Python package 使用两个包(名为pckg1pckg2 ),它们依赖于同一个名为 pckg3 的pckg3但来自两个不同的版本 显示依赖树:

$ pipenv graph
  pckg1==3.0.0
    - pckg3 [required: >=4.1.0]
  pckg2==1.0.2
    - pckg3 [required: ==4.0.11]

尝试安装依赖项:

$ pipenv install

Warning: Your dependencies could not be resolved. You likely have a mismatch in your sub-dependencies.
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.
Could not find a version that matches pckg3==4.0.11,==4.1.0,>=4.1.0 (from -r C:\Users\user\AppData\Local\Temp\pipenv-o7uxm080-requirements\pipenv-hwekv7dc-constraints.txt (line 2))
Tried: 3.3.1, 3.3.2, 3.3.3, 3.4.0, 3.4.2, 4.0.0, 4.0.0, 4.0.1, 4.0.1, 4.0.2, 4.0.2, 4.0.3, 4.0.3, 4.0.4, 4.0.4, 4.0.6, 4.0.6, 4.0.8, 4.0.8, 4.0.9, 4.0.9, 4.0.10, 4.0.10, 4.0.11, 4.0.11, 4.1.0, 4.1.0, 4.1.1, 4.1.1, 4.1.2, 4.1.2, 4.2.1, 4.2.1, 4.3.0, 4.3.0
There are incompatible versions in the resolved dependencies.

正如建议的那样, pip install --skip-lock可以解决问题,但依赖关系树仍未解决。

我很想告诉Pipenv覆盖pckg2的要求,并指定pckg3>=4.1.0

如何解决?

我不断收到该错误。 每次清除锁定文件中的缓存都非常有效。

$ pipenv lock --pre --clear

你不能。 目前, pipenv不提供任何显式覆盖需求约束的内容。

作为一种解决方法,您可以将要覆盖的依赖项放在dev-packages因为这些依赖项将被packages覆盖,因此此Pipfile应安装pckg3>=4.1.0

# Pipfile
...
[packages]
pckg1 = "==3.0.0"

[dev-packages]
pckg2 = "==1.0.2"

如果您现在锁定并安装:

$ pipenv lock --dev
$ pipenv install --dev

要求==4.0.11将被>=4.1.0覆盖。 如果您问我,这很丑陋,因为这不是开发包的用途,而且您正在更改项目中pckg2依赖项的角色,但我在这里看不到任何更好的方法。

当 pipfile 上有未完成的例程时,这会起作用。

一旦我犯了一个错误并运行

pipenv install codecove # With an 'e' at the end

并且 pipenv 一直试图完成安装但没有成功,因为 lib 不存在。 我解决了它:

pipenv uninstall codecove

并在之后安装了 codecov。

我试着跑

pipenv lock --clear
pipenv lock --pre --clear

但只有在卸载了错误名称的 lib 后,我才成功。

我有与google-cloud-core类似的问题。

$ pipenv lock
Locking [dev-packages] dependencies…
Locking [packages] dependencies…

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.
Could not find a version that matches google-cloud-core<0.29dev,<0.30dev,>=0.28.0,>=0.29.0
Tried: 0.20.0, 0.20.0, 0.21.0, 0.21.0, 0.22.0, 0.22.0, 0.22.1, 0.22.1, 0.23.0, 0.23.0, 0.23.1, 0.23.1, 0.24.0, 0.24.0, 0.24.1, 0.24.1, 0.25.0, 0.25.0, 0.26.0, 0.26.0, 0.27.0, 0.27.0, 0.27.1, 0.27.1, 0.28.0, 0.28.0, 0.28.1, 0.28.1, 0.29.0, 0.29.0
There are incompatible versions in the resolved dependencies.

它被解决了

  1. rm -rf pipfile.lock
  2. 管道更新

如果您收到如下错误:

Locking [dev-packages] dependencies…
Locking [packages] dependencies…
✘ Locking Failed! 

对我来说,这是因为底层虚拟环境没有引用我的当前目录。

我通过将内容移动到新目录并删除旧目录解决了这个问题。

我还必须删除PipfilePipfile.lock但我不确定是否有必要。

它发生在我身上,我正在使用 Visual Studio Code 并且能够摆脱它:

  • 从你的 python 文件夹中删除除 *.py 之外的所有文件(.vscode、 pycache 、* 该文件夹中的虚拟环境)
  • 创建一个新的 virtualenv env(name)
  • 新\\脚本\\激活.bat

然后尝试为虚拟文件夹安装缺少的依赖项,一切顺利,它对我有用。

如果你遇到了Locking Failed! 错误:

Locking [dev-packages] dependencies…
Locking [packages] dependencies…
✘ Locking Failed!

清除pipfile.lock的缓存卸载您的软件包并重新启动 VM对我来说很有效。

尝试:

pipenv uninstall *YourPackage*
pipenv uninstall *YourPackage* --dev   ##(if relevant to your package)
pipenv lock --clear

停止并销毁虚拟机

重启虚拟机

希望这可以帮助!

我对 glob 模块有类似的问题。 我从 Pipfile 中删除了glob = "*" ,之后它工作正常。

错误:

bash-4.2# pipenv lock  --clear
Locking [dev-packages] dependencies…
✔ Success! 
Locking [packages] dependencies…
✘ Locking Failed! 
[pipenv.exceptions.ResolutionFailure]:   File "/root/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pipenv/resolver.py", line 69, in resolve
[pipenv.exceptions.ResolutionFailure]:       req_dir=requirements_dir
[pipenv.exceptions.ResolutionFailure]:   File "/root/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pipenv/utils.py", line 726, in resolve_deps
[pipenv.exceptions.ResolutionFailure]:       req_dir=req_dir,
[pipenv.exceptions.ResolutionFailure]:   File "/root/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pipenv/utils.py", line 480, in actually_resolve_deps
[pipenv.exceptions.ResolutionFailure]:       resolved_tree = resolver.resolve()
[pipenv.exceptions.ResolutionFailure]:   File "/root/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pipenv/utils.py", line 395, in resolve
[pipenv.exceptions.ResolutionFailure]:       raise ResolutionFailure(message=str(e))
[pipenv.exceptions.ResolutionFailure]:       pipenv.exceptions.ResolutionFailure: ERROR: ERROR: Could not find a version that matches glob
[pipenv.exceptions.ResolutionFailure]:       No versions found
[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: ERROR: Could not find a version that matches glob
No versions found
Was https://pypi.org/simple reachable?
[pipenv.exceptions.ResolutionFailure]:       req_dir=requirements_dir
[pipenv.exceptions.ResolutionFailure]:   File "/root/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pipenv/utils.py", line 726, in resolve_deps
[pipenv.exceptions.ResolutionFailure]:       req_dir=req_dir,
[pipenv.exceptions.ResolutionFailure]:   File "/root/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pipenv/utils.py", line 480, in actually_resolve_deps
[pipenv.exceptions.ResolutionFailure]:       resolved_tree = resolver.resolve()
[pipenv.exceptions.ResolutionFailure]:   File "/root/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pipenv/utils.py", line 395, in resolve
[pipenv.exceptions.ResolutionFailure]:       raise ResolutionFailure(message=str(e))
[pipenv.exceptions.ResolutionFailure]:       pipenv.exceptions.ResolutionFailure: ERROR: ERROR: Could not find a version that matches glob
[pipenv.exceptions.ResolutionFailure]:       No versions found
[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: ERROR: Could not find a version that matches glob
No versions found
Was https://pypi.org/simple reachable?

在使用 VS Code 的 Windows 10 上,通过在 Powershell 中运行 pipenv,我得到了一个全新的安装。 我还删除了以前尝试的所有痕迹(新目录删除了以前的 venvs)。

这里没有什么对我有用。 最终解决了这个问题:

pip uninstall pipenv
pip install pipenv
pip install -U pipenv     

在 Ubuntu 21.04 - Hirsute Hippo - python 版本 3.9.5 上为我解决

此命令安装了这些软件包:

  • appdirs-1.4.4
  • 证书 2021.5.30
  • distlib-0.3.2
  • filelock-3.0.12
  • pipenv-2021.5.29
  • 六-1.16.0
  • virtualenv-20.4.7
  • virtualenv-clone-0.5.4

在 virtualenv 中更新pip对我有用: py -m pip install --upgrade pip

这也可能是因为您有一个旧的 pipenv 环境,您需要在创建新环境之前清理它。

pipenv --rm
pipenv install
pipenv lock
Locking [dev-packages] dependencies…
Locking [packages] dependencies…

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.

pipenv 安装 --clean

vi Pipfile 并删除有问题的包。 为我工作得很好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM