[英]How to resolve Python package dependencies with pipenv?
I am using pipenv
to handle Python package dependencies.我正在使用
pipenv
来处理 Python package 依赖项。
The Python package is using two packages (named pckg1
and pckg2
) that rely on the same package named pckg3
, but from two different versions . Python package 使用两个包(名为
pckg1
和pckg2
),它们依赖于同一个名为 pckg3 的pckg3
,但来自两个不同的版本。 Showing the dependency tree:显示依赖树:
$ pipenv graph
pckg1==3.0.0
- pckg3 [required: >=4.1.0]
pckg2==1.0.2
- pckg3 [required: ==4.0.11]
An attempt to install dependencies:尝试安装依赖项:
$ 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.
As suggested, pip install --skip-lock
does the trick, but the dependency tree is still unresolved.正如建议的那样,
pip install --skip-lock
可以解决问题,但依赖关系树仍未解决。
I would love to tell Pipenv
to override pckg2
's requirement, and specify pckg3>=4.1.0
.我很想告诉
Pipenv
覆盖pckg2
的要求,并指定pckg3>=4.1.0
。
How can this be resolved?如何解决?
I get that error constantly.我不断收到该错误。 Clearing the cache in the lock file works beautifully every time.
每次清除锁定文件中的缓存都非常有效。
$ pipenv lock --pre --clear
You can't.你不能。 At the moment,
pipenv
doesn't offer anything for an explicit override of requirement constraints.目前,
pipenv
不提供任何显式覆盖需求约束的内容。
As a workaround, you can put dependencies that you want to override to dev-packages
as those will be overridden by packages
, so this Pipfile
should install pckg3>=4.1.0
:作为一种解决方法,您可以将要覆盖的依赖项放在
dev-packages
因为这些依赖项将被packages
覆盖,因此此Pipfile
应安装pckg3>=4.1.0
:
# Pipfile
...
[packages]
pckg1 = "==3.0.0"
[dev-packages]
pckg2 = "==1.0.2"
If you now lock and install:如果您现在锁定并安装:
$ pipenv lock --dev
$ pipenv install --dev
the requirement ==4.0.11
will be overridden by >=4.1.0
.要求
==4.0.11
将被>=4.1.0
覆盖。 This is ugly if you ask me because this is not what development packages are meant for and you're changing the role of pckg2
dependency in project, but I don't see any better way here.如果您问我,这很丑陋,因为这不是开发包的用途,而且您正在更改项目中
pckg2
依赖项的角色,但我在这里看不到任何更好的方法。
This works when there are unfinished routines on pipfile.当 pipfile 上有未完成的例程时,这会起作用。
Once I made a mistake and run一旦我犯了一个错误并运行
pipenv install codecove # With an 'e' at the end
and the pipenv kept always trying to complete the installation with no success because the lib does not exist.并且 pipenv 一直试图完成安装但没有成功,因为 lib 不存在。 I resolved it with:
我解决了它:
pipenv uninstall codecove
and installed codecov after.并在之后安装了 codecov。
I tried to run我试着跑
pipenv lock --clear
pipenv lock --pre --clear
but only after uninstalled the lib with wrong name I succeeded.但只有在卸载了错误名称的 lib 后,我才成功。
I have the similar issue with google-cloud-core
.我有与
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.
It was solved by它被解决了
If you get an error like:如果您收到如下错误:
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
✘ Locking Failed!
For me, this happened because the underlying virtual environment did not refer to my current directory.对我来说,这是因为底层虚拟环境没有引用我的当前目录。
I solved this problem by moving the contents to a new directory and deleting the old one.我通过将内容移动到新目录并删除旧目录解决了这个问题。
I also had to delete the Pipfile
and Pipfile.lock
but I'm not sure if that's necessary.我还必须删除
Pipfile
和Pipfile.lock
但我不确定是否有必要。
It happened the same to me, I'm working with Visual Studio Code and I was able to get rid o it:它发生在我身上,我正在使用 Visual Studio Code 并且能够摆脱它:
and then try to install the missing dependencies for the virtual folder and good to go, it worked for me.然后尝试为虚拟文件夹安装缺少的依赖项,一切顺利,它对我有用。
If you ran into the Locking Failed!
如果你遇到了
Locking Failed!
error:错误:
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
✘ Locking Failed!
Clearing the cache on pipfile.lock
, uninstalling your package and restarting the VM did the trick for me.清除
pipfile.lock
上的缓存,卸载您的软件包并重新启动 VM对我来说很有效。
Try:尝试:
pipenv uninstall *YourPackage*
pipenv uninstall *YourPackage* --dev ##(if relevant to your package)
pipenv lock --clear
stop & destroy VM停止并销毁虚拟机
restart VM重启虚拟机
Hope this helps!希望这可以帮助!
I had similar issue with glob module.我对 glob 模块有类似的问题。 I deleted
glob = "*"
from Pipfile and it worked fine after that.我从 Pipfile 中删除了
glob = "*"
,之后它工作正常。
Error:错误:
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?
On Windows 10 using VS Code I got a clean install after much messing about by running pipenv in Powershell.在使用 VS Code 的 Windows 10 上,通过在 Powershell 中运行 pipenv,我得到了一个全新的安装。 I also deleted all traces of the previous tries (new directory deleted the previous venvs).
我还删除了以前尝试的所有痕迹(新目录删除了以前的 venvs)。
Nothing here worked for me.这里没有什么对我有用。 In the end this solved the issue:
最终解决了这个问题:
pip uninstall pipenv
pip install pipenv
pip install -U pipenv
solved for me on Ubuntu 21.04 - Hirsute Hippo - python Version 3.9.5在 Ubuntu 21.04 - Hirsute Hippo - python 版本 3.9.5 上为我解决
This command installed those packages:此命令安装了这些软件包:
Updating pip
inside the virtualenv worked for me: py -m pip install --upgrade pip
在 virtualenv 中更新
pip
对我有用: py -m pip install --upgrade pip
This could also be because you had an old pipenv environment and you need to clean it before you create a new one.这也可能是因为您有一个旧的 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 install --clean pipenv 安装 --clean
vi Pipfile and remove the offending packages. vi Pipfile 并删除有问题的包。 Worked nicely for me.
为我工作得很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.