我的主要开发机器是x86_64
虽然我的一些部署环境是arm7vl
(树莓派)。对于大多数 Python 开发来说,这不是问题,但某些 Python 库只能在PyPI https://pypi.org/ for x86_64
or piwheels https://piwheels.org/ for aarmv7l
。这导致使用诗歌遇到一些困难。作为一个简单的例子,这是一个pyproject.toml
文件创建于x86_64
机器:
[tool.poetry]
name = "poetrytest"
version = "0.1.0"
description = ""
authors = ["Your Name <[email protected] /cdn-cgi/l/email-protection>"]
[tool.poetry.dependencies]
python = "^3.9"
opencv-python = "^4.5.5"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
相应的poetry.lock
文件包含从 PyPI 中提取的文件的哈希值,当您运行时poetry install
一切都按预期进行。However,如果将这两个文件复制到 Raspberry Pi,安装将无法找到合适的.whl
文件,因此退回到尝试从源代码构建,这大约需要 2 小时并且失败:-(
要使其在 Pi 上工作,您需要将此块添加到pyproject.toml
:
[[tool.poetry.source]]
name = "piwheels"
url = "https://www.piwheels.org/simple/"
...然后删除poetry.lock
并运行poetry install
。这将重新生成锁定文件(现在包含来自 piwheels.org 的条目)并按预期安装所有内容。然而这并不是很有用,因为这意味着我无法版本控制pyproject.toml
or poetry.lock
。我也无法将上述源代码片段包含在原始文件中pyproject.toml
文件,或构建x86_64
机器模具Unable to find installation candidates
.
到目前为止,我能找到的唯一跨平台方法是让所有内容都保持版本控制x86_64
当我想安装某些东西时,只需在 Pi 上运行它即可:
$ poetry export --without-hashes > requirements.txt
$ pip install --requirement requirements.txt
这……很糟糕。当然,一定有更好的方法吗?