如何使用 pipenv 解决 Python 包依赖?
How to resolve Python package dependencies with pipenv?
我正在使用 pipenv
来处理 Python 包依赖关系。
Python 包正在使用两个包(名为 pckg1
和 pckg2
),它们依赖于名为 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
不提供任何明确覆盖需求约束的功能。
作为解决方法,您可以将要覆盖的依赖项放入 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
依赖项在项目中的作用,但我在这里看不到更好的方法。
我经常遇到这个错误。每次清除锁定文件中的缓存都非常有效。
$ pipenv lock --pre --clear
我遇到了与 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.
解决了
- rm -rf Pipfile.lock
- pipenv 更新
我对 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?
如果您收到如下错误:
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
✘ Locking Failed!
对我来说,这是因为底层虚拟环境没有引用我的当前目录。
我通过将内容移动到新目录并删除旧目录解决了这个问题。
我还必须删除 Pipfile
和 Pipfile.lock
,但我不确定是否有必要。
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
我也遇到了同样的情况,我正在使用 Visual Studio 代码并且我能够摆脱它:
- 从您的 python 文件夹中删除除 *.py 之外的所有文件(.vscode、pycache、* 该文件夹中的虚拟环境)
- 创建一个新的 virtualenv 环境(名称)
- new\scripts\activate.bat
然后尝试为虚拟文件夹安装缺少的依赖项,一切顺利,它对我有用。
在 Windows 10 上,使用 VS Code 我在 Powershell 中 运行 pipenv 乱七八糟之后得到了全新安装。我也删除了之前尝试的所有痕迹(新目录删除了之前的venvs)。
这在 pipfile 上有未完成的例程时有效。
有一次我犯了错误 运行
pipenv install codecove # With an 'e' at the end
并且 pipenv 一直试图完成安装但没有成功,因为 lib 不存在。我解决了它:
pipenv uninstall codecove
并在之后安装了 codecov。
我试过 运行
pipenv lock --clear
pipenv lock --pre --clear
但只有在卸载了名称错误的库后我才成功。
这里没有对我有用的东西。最终这解决了问题:
pip uninstall pipenv
pip install pipenv
如果你运行进入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
停止并销毁 VM
重启虚拟机
希望对您有所帮助!
pip install -U pipenv
为我解决了 Ubuntu 21.04 - 多毛河马 - python 版本 3.9.5
此命令安装了那些软件包:
- appdirs-1.4.4
- certifi-2021.5.30
- distlib-0.3.2
- filelock-3.0.12
- pipenv-2021.5.29
- 6-1.16.0
- virtualenv-20.4.7
- virtualenv-clone-0.5.4
在 virtualenv 中更新 pip
对我有用:py -m pip install --upgrade pip
我正在使用 pipenv
来处理 Python 包依赖关系。
Python 包正在使用两个包(名为 pckg1
和 pckg2
),它们依赖于名为 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
不提供任何明确覆盖需求约束的功能。
作为解决方法,您可以将要覆盖的依赖项放入 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
依赖项在项目中的作用,但我在这里看不到更好的方法。
我经常遇到这个错误。每次清除锁定文件中的缓存都非常有效。
$ pipenv lock --pre --clear
我遇到了与 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.
解决了
- rm -rf Pipfile.lock
- pipenv 更新
我对 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?
如果您收到如下错误:
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
✘ Locking Failed!
对我来说,这是因为底层虚拟环境没有引用我的当前目录。
我通过将内容移动到新目录并删除旧目录解决了这个问题。
我还必须删除 Pipfile
和 Pipfile.lock
,但我不确定是否有必要。
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
我也遇到了同样的情况,我正在使用 Visual Studio 代码并且我能够摆脱它:
- 从您的 python 文件夹中删除除 *.py 之外的所有文件(.vscode、pycache、* 该文件夹中的虚拟环境)
- 创建一个新的 virtualenv 环境(名称)
- new\scripts\activate.bat
然后尝试为虚拟文件夹安装缺少的依赖项,一切顺利,它对我有用。
在 Windows 10 上,使用 VS Code 我在 Powershell 中 运行 pipenv 乱七八糟之后得到了全新安装。我也删除了之前尝试的所有痕迹(新目录删除了之前的venvs)。
这在 pipfile 上有未完成的例程时有效。
有一次我犯了错误 运行
pipenv install codecove # With an 'e' at the end
并且 pipenv 一直试图完成安装但没有成功,因为 lib 不存在。我解决了它:
pipenv uninstall codecove
并在之后安装了 codecov。
我试过 运行
pipenv lock --clear
pipenv lock --pre --clear
但只有在卸载了名称错误的库后我才成功。
这里没有对我有用的东西。最终这解决了问题:
pip uninstall pipenv
pip install pipenv
如果你运行进入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
停止并销毁 VM
重启虚拟机
希望对您有所帮助!
pip install -U pipenv
为我解决了 Ubuntu 21.04 - 多毛河马 - python 版本 3.9.5
此命令安装了那些软件包:
- appdirs-1.4.4
- certifi-2021.5.30
- distlib-0.3.2
- filelock-3.0.12
- pipenv-2021.5.29
- 6-1.16.0
- virtualenv-20.4.7
- virtualenv-clone-0.5.4
在 virtualenv 中更新 pip
对我有用:py -m pip install --upgrade pip