如何解决Python诗歌依赖错误

Ser*_*ema 8 python-3.x python-poetry pre-commit.com

当尝试使用 Poetry 安装 Python 依赖项时,出现以下错误:

$ poetry install                                                                                                    
The currently activated Python version 2.7.15 is not supported by the project (>=3.6).
Trying to find and use a compatible version.
Using python3 (3.7.4)
Skipping virtualenv creation, as specified in config file.
Updating dependencies
Resolving dependencies... (1.7s)

[SolverProblemError]
The current project's Python requirement (>=3.6) is not compatible with some of the required packages Python requirement:
  - pre-commit requires Python >=3.6.1

Because no versions of pre-commit match >2.2.0,<3.0.0
 and pre-commit (2.2.0) requires Python >=3.6.1, pre-commit is forbidden.
So, because my-proj depends on pre-commit (^2.2.0), version solving failed.
Run Code Online (Sandbox Code Playgroud)

这是我的环境:

$ python3 --version                                                                                                 
Python 3.7.4
$ poetry --version                                                                                                  
Poetry version 1.0.5
$ pre-commit --version                                                                                             
pre-commit 2.2.0
Run Code Online (Sandbox Code Playgroud)

以及我的 pyproject.toml 的示例:

...
[tool.poetry.dependencies]
python = ">=3.6"
...

[tool.poetry.dev-dependencies]
pre-commit = "^2.2.0"
...
Run Code Online (Sandbox Code Playgroud)

我尝试将 pyproject 中的 python 版本更改为 3.7,但没有改变结果。如果我删除预提交依赖项,我会在另一个依赖项上遇到相同的错误。

我不知道应该寻找什么:升级/降级版本、不兼容的版本

Ser*_*ema 6

正如@Arne 在评论中提到的,这似乎是一个 virtualenv 问题。

我之前运行过poetry config virtualenvs.create false另一个项目,并且配置是在全局级别设置的。运行反向命令poetry config virtualenvs.create true解决了问题(也许添加--local将其设置为单个项目)。