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

pip install with relative paths in poetry

如何指定 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, so for dependencies the format is 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.

我天真地认为所有路径都必须是绝对路径。


相关: