Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pip install with relative paths in poetry

How do I specify relative paths that pip can use in poetry's pyproject.toml?

poetry successfully installs them, however pip fails with the following error:

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

Example

I have the following repository structure

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

main_app is dependent upon lib_foo, its dependecies looks like this:
./main_app/pyproject.toml

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

when doing:

./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)


I am using poetry when developing a project however when deploying them I want to only use pip


A related issue

like image 835
moshevi Avatar asked Oct 20 '25 04:10

moshevi


1 Answers

I am pretty sure pip can not handle dependencies with relative paths. Absolute paths might be okay.

The way I see it, pip gets dependencies in the core metadata format, so for dependencies the format is PEP 508, which says:

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.

And PEP 440 says (emphasis mine):

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.

Which I naively interpret as all paths must be absolute.


Related:

  • https://github.com/pypa/pip/issues/9127
  • https://github.com/python-poetry/poetry/issues/3148
like image 108
sinoroc Avatar answered Oct 22 '25 04:10

sinoroc