我最近安装了 Pyenv 和 Poetry,想创建一个新的 Python 3.8 项目。 I’ve set both the global
and local
versions of python to 3.8.1
using the appropriate Pyenv commands ( pyenv global 3.8.1
for example).当我在终端中运行 pyenv version
时,输出为 3.8.1.
正如预期的那样。
现在,问题是当我用 Poetry ( poetry new my-project
) 创建一个新的 python 项目时,生成的 pyproject.toml
文件用 python 2.7 创建了一个项目:
[tool.poetry]
name = "my-project"
version = "0.1.0"
description = ""
authors = ["user <user@email.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"
Poetry 好像默认回系统版本的 Python。我如何更改它以便它使用与 Pyenv 一起安装的版本?
编辑
我正在使用与 Python 2.7 捆绑在一起的 MacOS。我认为这可能会导致这里出现一些问题。我已经用 Pyenv 重新安装了 Python 3.8,但是当我点击 Poetry install
时,我收到以下错误:
The currently activated Python version 2.7.16 is not supported by the project (^3.8).
Trying to find and use a compatible version.
[NoCompatiblePythonVersionFound]
Poetry was unable to find a compatible version. If you have one, you can explicitly use it via the "env use" command.
我应该使用 Pyenv 为项目明确创建环境,还是项目应该能够在运行后访问正确的 Python 版本 pyenv local 3.8.1.
?当我做后者时,什么都没有改变,我仍然得到同样的错误。
原文由 P4nd4b0b3r1n0 发布,翻译遵循 CC BY-SA 4.0 许可协议
好吧,我想通了这个问题。有点尴尬的是,在运行任何其他命令之前,我没有运行
pyenv shell 3.8.1
。现在一切正常。谢谢大家的努力。