我用 Poetry 创建了一个 python 项目“foo”。这是以下内容pyproject.toml:
[tool.poetry]
name = "bar"
version = "0.1.0"
description = ""
[tool.poetry.dependencies]
python = ">=3.5"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
Run Code Online (Sandbox Code Playgroud)
该包兼容Python3.5。我想要黑色格式化程序,它与Python3.5不兼容。我觉得使用Python>=3.6开发是没有问题的,但是无法安装black formatter:
[tool.poetry]
name = "bar"
version = "0.1.0"
description = ""
[tool.poetry.dependencies]
python = ">=3.5"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
Run Code Online (Sandbox Code Playgroud)
所以我直接安装了黑色pip:
$ poetry add black --dev
[SolverProblemError]
The current project's Python requirement (>=3.5) is not compatible with some of the required packages Python …Run Code Online (Sandbox Code Playgroud) 我们有一个私有的 git monorepo,它托管着许多 Python 包。Poetry 是最初为该项目选择的依赖管理工具。无论如何,由于这个 Poetry 问题,涉及创建新文件的解决方案不会被接受setup.py。
结构的简化版本:
\ngit-monorepo\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pkg-1\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pkg\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 mod1.py\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 pyproject.toml\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pkg-2\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pkg\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 mod2.py\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 pyproject.toml\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 lib\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pkg\n \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 lib.py\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 pyproject.toml\nRun Code Online (Sandbox Code Playgroud)\n库分发包lib独立于任何其他包。然而,pkg-1取决于lib且pkg-2取决于pkg-1和lib。
所以,问题是:
\npip从这个 monorepo 安装软件包的正确方法是什么?
让我们考虑一下我们尝试安装的示例pkg-1,其中pkg-1/pyproject.toml包括以下行:
...\n\n[tool.poetry.dependencies]\nlib = {path = "../lib/"}\n\n...\nRun Code Online (Sandbox Code Playgroud)\n运行结果,如VCS 支持文档pip中所述:
我想使用诗歌将多个私有 Github 存储库作为 python 包安装到我的存储库中。这在poetry install本地运行时效果很好,因为我将公共 SSH 密钥添加到 Github,这允许诗歌访问私有存储库。问题是我想在我的 CI/CD 管道中安装这些相同的私有包,为此我需要为每个 repo 添加一个部署密钥。正确的部署密钥需要用于正确的存储库,为了使其工作,我需要使用以下格式的一些别名设置一个配置(我实际上还没有知道这是否真的有效) ):
// /.ssh/config
Host repo-1.github.com
IdentityFile ~/.ssh/repo-1-deploy-key
Host repo-2.github.com
IdentityFile ~/.ssh/repo-2-deploy-key
Run Code Online (Sandbox Code Playgroud)
凡repo-1和repo-2是私有仓库我需要安装的名称。在本地运行时,pyproject.toml需要按以下格式设置包:
// pyproject.toml
...
[tool.poetry.dependencies]
repo-1 = { git = "ssh://git@github.com/equinor/repo-1.git" }
repo-2 = { git = "ssh://git@github.com/equinor/repo-2.git" }
...
Run Code Online (Sandbox Code Playgroud)
因为这将允许开发人员在没有任何配置的情况下安装软件包(假设他们有权访问)。然而,对于 CI/CD 管道,URL 需要匹配 SSH 配置文件中的别名,因此它需要看起来像这样:
// pyproject.toml
...
[tool.poetry.dependencies]
repo-1 = { git = "ssh://git@repo-1.github.com/equinor/repo-1.git" }
repo-2 = { git = "ssh://git@repo-2.github.com/equinor/repo-2.git" }
...
Run Code Online (Sandbox Code Playgroud)
现在,我似乎陷入困境的是如何在同一个 pyproject …
当我尝试poetry add cryptography在 Python 3.9.0 虚拟环境中使用 Python Poetry 1.1.4 包管理器 ( ) 安装加密模块时,我得到:
error: can't find Rust compiler
If you are using an outdated pip version, it is possible a prebuilt wheel is available for this package but pip is not able to install from it. Installing from the wheel would avoid the need for a Rust compiler.
To update pip, run:
pip install --upgrade pip
and then retry package installation.
If you did intend to build this …Run Code Online (Sandbox Code Playgroud) 使用 python-poetry,我想根据安装过程中传递的额外内容安装不同的软件包版本。例如我想
# when extra == 'a', install numpy == 1.20.0
$ poetry install -E a
# when extra == 'b', install numpy == 1.19.0
$ poetry install -E b
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下 toml 文件
[tool.poetry]
name = "demo-poetry"
version = "0.1.0"
description = ""
authors = ["tenticon"]
[tool.poetry.dependencies]
python = "^3.8"
numpy = [
{ version = "1.20.0", markers = "extra == 'a'", optional = true},
{ version = "1.19.0", markers = "extra == 'b'", optional = true}
]
[tool.poetry.extras]
a …Run Code Online (Sandbox Code Playgroud) 我的项目 A 带有这样的 pyproject 文件
[tool.poetry]
name = "projectA"
version = "2.0"
description = "Package gathering for project A"
repository = "https://git.saas.tech/project-a"
[tool.poetry.dependencies]
Package B = "1.0"
Run Code Online (Sandbox Code Playgroud)
我想测试一个功能。我如何告诉诗歌查看特定的分支?这可能吗 ?
repository = "https://git.saas.tech/project-a/my-feature"
Run Code Online (Sandbox Code Playgroud) 当我运行诗歌命令时,我收到消息:
Skipping virtualenv creation, as specified in config file.
Run Code Online (Sandbox Code Playgroud)
我不记得设置过这样的东西,并且我在 pyproject.toml 中没有真正看到任何相关内容。诗歌谈论的是什么配置文件?
我在一些 python 项目中使用 Poetry。在某个阶段我想重命名项目的根文件夹并不罕见。当我这样做并运行poetry shell诗歌时,会创建一个新的虚拟环境。但我不需要新的虚拟环境,我只想继续使用现有的虚拟环境。我知道我可以通过运行手动激活旧环境source {path to the old venv}/bin/activate,但随后我必须单独跟踪旧环境名称并避免使用poetry shell.
我能做点什么吗?再次开始安装依赖项、将 IDE 指向新环境并删除旧的虚拟环境是相当耗时的,只是因为您更改了根文件夹名称 - 这种情况可能会发生多次。这个问题表明该问题没有解决方案,但想确认这一点,因为对我来说这似乎是相当烦人的问题。
使用官方安装程序在 macOS 11.6/Xcode 13 上安装新诗失败:
u@s-MacBook-Pro ~ % curl -sSL https://install.python-poetry.org | python3 -
Retrieving Poetry metadata
# Welcome to Poetry!
This will download and install the latest version of Poetry,
a dependency and package manager for Python.
It will add the `poetry` command to Poetry's bin directory, located at:
/Users/u/Library/Python/3.8/bin
You can uninstall at any time by executing this script with the --uninstall option,
and these changes will be reverted.
Installing Poetry (1.1.12): An error occurred. Removing partial environment. …Run Code Online (Sandbox Code Playgroud) 最新的预览版支持在 M1 MacBook Pro 上进行加速训练。目前仅最新预览版(每晚)版本支持此功能:
\n\n\n首先,只需在运行 macOS 12.3 或更高版本以及原生 Python 版本 (arm64) 的 Apple Silicon Mac 上安装最新的预览版(每晚)版本即可。
\n
根据文档,这是通过以下方式安装最新预览版本的方法pip:
pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu\nRun Code Online (Sandbox Code Playgroud)\n但我正在使用Poetry来管理我的 Python 项目依赖项。
\n诗歌似乎不支持该--pre选项:
$ poetry add --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu \n\n Stack trace:\n\n 11 ~/.poetry/lib/poetry/_vendor/py3.9/clikit/console_application.py:123 in run\n io = io_factory(\n\n 10 ~/.poetry/lib/poetry/console/config/application_config.py:221 in create_io\n resolved_command = application.resolve_command(args)\n\n 9 ~/.poetry/lib/poetry/_vendor/py3.9/clikit/console_application.py:110 in resolve_command\n return self._config.command_resolver.resolve(args, …Run Code Online (Sandbox Code Playgroud) python-poetry ×10
python ×8
pip ×2
deploy-keys ×1
git ×1
github ×1
macos ×1
monorepo ×1
pytorch ×1
ssh ×1