gpt4 book ai didi

在诗歌中使用相对路径进行 pip 安装

转载 作者:行者123 更新时间:2023-12-04 08:35:49 30 4
gpt4 key购买 nike

如何指定 pip 可以在 poetrypyproject.toml 中使用的相对路径?

poetry 成功安装它们,但是 pip 失败并出现以下错误:

File "/tmp/pip-build-env-ck09aiax/overlay/lib/python3.7/site-packages/poetry/core/packages/directory_dependency.py", line 36, in __init__
raise ValueError("Directory {} does not exist".format(self._path))
ValueError: Directory ../lib_foo does not exist

示例

我有以下存储库结构

.
├── lib_foo
│ ├── lib_foo
│ │ └── __init__.py
│ └── pyproject.toml
└── main_app
├── main_app
│ └── __init__.py
└── pyproject.toml

main_app 依赖于 lib_foo,它的依赖如下:
./main_app/pyproject.toml

[tool.poetry.dependencies]
python = "^3.7"
lib-foo = { path = "../lib_foo" } # also tried path = "../lib_foo/"

做的时候:

./main_app$ poetry install  # runs successfully 
./main_app$ python -m pip install ../lib_foo/ # runs successfully
./main_app$ python -m pip install . # fails with the error mentioned above
./main_app$ python -m pip --version
pip 20.1.1 from ./main_app/my_venv/lib/python3.7/site-packages/pip (python 3.7)


我在开发项目时使用 poetry 但是在部署它们时我只想使用 pip


一个相关issue

最佳答案

我很确定 pip 无法处理相对路径的依赖关系。绝对路径可能没问题。

在我看来,pipcore metadata format 中获取依赖项,因此对于依赖项,格式为 PEP 508 ,它说:

the URL reference form, specified in PEP-440 [4] is not actually implemented in pip, but since PEP-440 is accepted, we use that format rather than pip's current native format.

PEP 440说(强调我的):

File URLs take the form of file://<host>/<path>. If the <host> is omitted it is assumed to be localhost and even if the <host> is omitted the third slash MUST still exist.

我天真地将其解释为所有路径都必须是绝对路径。


相关:

关于在诗歌中使用相对路径进行 pip 安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64807176/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com