python - 诗歌将python版本更改为3.x
问题描述
根据poetry的文档,设置新项目的正确方法是 with poetry new poetry-demo
,但是这会通过创建以下 toml 文件来创建一个基于现已弃用的 python2.7 的项目:
[tool.poetry]
name = "poetry-demo"
version = "0.1.0"
description = ""
authors = ["Harsha Goli <harshagoli@gmail.com>"]
[tool.poetry.dependencies]
python = "^2.7"
[tool.poetry.dev-dependencies]
pytest = "^4.6"
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
如何将其更新到 3.7?运行时只需更改python = "^2.7"
为python = "^3.7"
会导致以下错误poetry install
:
[SolverProblemError]
The current project's Python requirement (2.7.17) is not compatible with some of the required packages Python requirement:
- zipp requires Python >=3.6
Because no versions of pytest match >=4.6,<4.6.9 || >4.6.9,<5.0
and pytest (4.6.9) depends on importlib-metadata (>=0.12), pytest (>=4.6,<5.0) requires importlib-metadata (>=0.12).
And because no versions of importlib-metadata match >=0.12,<1.5.0 || >1.5.0
and importlib-metadata (1.5.0) depends on zipp (>=0.5), pytest (>=4.6,<5.0) requires zipp (>=0.5).
Because zipp (3.1.0) requires Python >=3.6
and no versions of zipp match >=0.5,<3.1.0 || >3.1.0, zipp is forbidden.
Thus, pytest is forbidden.
So, because poetry-demo depends on pytest (^4.6), version solving failed.
解决方案
每当您手动更改依赖项时,pyproject.toml
您都必须注意以下几点:
之后运行
poetry lock
或删除poetry.lock
文件以强制重新创建它。poetry install
这样做的原因是,poetry.lock
如果可以找到一个而不是pyproject.toml
.如果您更改 python 版本并使用项目内 virtualenv,请删除
.venv
运行前的poetry install
. 诗歌一旦创建就不会更改 venv 的 python 版本,因为它使用 python 版本本身来创建 virtualenv。
推荐阅读
- javascript - 异步调用链,其中最后一个调用比较第一个调用的内容
- python - 获取以给定字符串开头的列中的唯一项
- flask - 在烧瓶应用程序中导入模块的问题
- jupyter-notebook - 如何获取 IPython 或 Jupyter 笔记本中最近执行的“执行计数”?
- r - 基于某个值的子集数据框
- python - 张量的 tf.print 问题(无法打印单个值)
- umbraco - Umbraco 8 - 隐藏成员组
- javascript - 如何配置 socket.io 来监听客户端
- c# - 配置文件 - 加密连接字符串
- react-native - 反应导航 v4 到 v5 问题