Python 3.x 如何解决Python依赖错误

Python 3.x 如何解决Python依赖错误,python-3.x,python-poetry,pre-commit.com,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 f

在尝试使用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.
还有我的pyproject.toml示例:

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

[tool.poetry.dev-dependencies]
pre-commit = "^2.2.0"
...
我尝试将pyproject中的python版本更改为3.7,但没有更改结果。如果我删除了预提交依赖项,那么在另一个依赖项上也会出现相同的错误


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

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


我以前为另一个项目运行过
poyment-config-virtualenvs.create-false
,配置是在全局级别设置的。运行reverse命令
poetry config virtualenvs.create true
解决了问题(可能添加
--local
将其设置为单个项目)。

好吧,如果将其更改为
“>=3.6.1怎么办
pyproject.toml
中?如果我将其更改为
>=3.6.1
,它现在似乎与python 2.7进行比较:
当前项目的python需求(2.7.15)与Python要求的某些必需包不兼容:-预提交要求Python>=3.6.1
poetry.tool
部分中更改某些内容后,您需要重新安装应用程序,以便poetry可以使用新规范重建virtualenv。另外,从错误消息来看,您似乎通过
virtualenv
激活了某种python环境,可能在运行
poetry install
之前运行
deactivate
。这并不是一个与编程或工具相关的问题,而是您的本地设置给您带来了问题。这里给出的任何帮助最终都会归结为“尽量保持一个干净的设置,尽可能地遵守诗歌说明。”你是对的@Arne。不久前,我运行了
poetry config virtualenvs.create false
,但没有为项目正确创建virtualenv。运行
poetry config virtualenvs.create true
后,一切正常。
...
[tool.poetry.dependencies]
python = ">=3.6"
...

[tool.poetry.dev-dependencies]
pre-commit = "^2.2.0"
...