我想基于操作系统平台约束一个 * 单一 * 依赖项(即,一个包只有一个名称)。例如,包版本或包源(URL、本地轮等)可以根据0S而改变。
我尝试了文档中链接的解决方案,但不起作用。Poetry尝试为错误的操作系统平台安装错误的软件包。我还搜索了StackOverflow,发现了1个相关问题,但没有帮助。
作为一个实际的用例,我想在macOS上从PyPI安装PyTorch 2.0.1,在Ubuntu上安装一个特定的轮子(使用特定版本的CUDA)。因此,我的包规格是:
[tool.poetry.dependencies]
python = "^3.10"
torch = [
{platform = "linux", url = "https://download.pytorch.org/whl/cu118/torch-2.0.1%2Bcu118-cp310-cp310-linux_x86_64.whl"},
{platform = "darwin", version = "2.0.1"},
]
不幸的是,在macOS上,Poetry试图安装错误消息中提到的Linux软件包:
Installing dependencies from lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing torch (2.0.1+cu118 https://download.pytorch.org/whl/cu118/torch-2.0.1%2Bcu118-cp310-cp310-linux_x86_64.whl): Failed
RuntimeError
Package https://download.pytorch.org/whl/cu118/torch-2.0.1%2Bcu118-cp310-cp310-linux_x86_64.whl cannot be installed in the current environment {'implementation_name': 'cpython', 'implementation_version': '3.10.11', 'os_name': 'posix', 'platform_machine': 'arm64', 'platform_release': '22.5.0', 'platform_system': 'Darwin', 'platform_version': 'Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000', 'python_full_version': '3.10.11', 'platform_python_implementation': 'CPython', 'python_version': '3.10', 'sys_platform': 'darwin', 'version_info': [3, 10, 11, 'final', 0], 'interpreter_name': 'cp', 'interpreter_version': '3_10'}
at ~/Library/Application Support/pypoetry/venv/lib/python3.10/site-packages/poetry/installation/executor.py:788 in _download_link
784│ # Since we previously downloaded an archive, we now should have
785│ # something cached that we can use here. The only case in which
786│ # archive is None is if the original archive is not valid for the
787│ # current environment.
→ 788│ raise RuntimeError(
789│ f"Package {link.url} cannot be installed in the current environment"
790│ f" {self._env.marker_env}"
791│ )
792│
请不要以为我通过运行poetry lock
确保锁文件与pyproject.toml
一致。
这个问题有解决办法吗?
1条答案
按热度按时间nhn9ugyo1#
我找到了一个不完全令人满意的解决办法。这适用于我的具体情况,但不适用于其他情况。它包括为每个操作系统平台指定精确和显式的wheel URL,而不是依赖于PyPI for macOS: