python-poetry / poetry

Python packaging and dependency management made easy
https://python-poetry.org
MIT License
30.51k stars 2.23k forks source link

System site packages is not seen as a Python package #8521

Open niniack opened 9 months ago

niniack commented 9 months ago

Issue

My poetry install consistently fails with the error

Directory /usr/local/lib/python3.8/dist-packages for torch does not seem to be a Python package

Here is the gist that shows the verbose output of the failure. None of the packages get installed

I am using an NVIDIA Pytorch container that has torch configured as I need it. I would like to use Poetry to manage my project. Ideally, I would like Poetry to handle everything except my torch and torchvision dependencies.

In order to achieve this, I am always sure to:

  1. run poetry config virtualenvs.options.system-site-packages true
  2. pin torch = { version = "1.14.0a0+410ce96", allow-prereleases = true} in my pyproject.toml

When I run poetry lock, this is what the seection for torch looks like

...
[[package]]
name = "torch"
version = "1.14.0a0+410ce96"
description = "Tensors and Dynamic neural networks in Python with strong GPU acceleration"
optional = false
python-versions = "*"
files = []
develop = false

[package.source]
type = "directory"
url = "../../usr/local/lib/python3.8/dist-packages"
...

This comment in in PR #8359 caught my eye.

IMO, it would be nice to have a test in test_installed_repository.py that checks that a package from system site packages does not have source_type == "directory".

If a system site package was to be seen as a directory, would that mean this patch would fail?

I've tried to remove [package.source in the lock file and poetry install still fails. Here is the verbose output.

Removing just the source so that the lock file looks like:

[package.source]
url = "../../usr/local/lib/python3.8/dist-packages"

gives the same result.

Ultimately, I would like to pin my torch package in my toml file, use system-site-packages in my venv, not mess with the lock file, and have poetry accept my installation as a Python package that already exists and doesn't need to be updated/reinstalled

dimbleby commented 9 months ago

smells like there's an unwanted direct_url.json lying around on the docker image; else why would poetry think that this was a directory dependency?

dimbleby commented 8 months ago

might be fixed, or anyway progressed, by #8549

however

niniack commented 8 months ago

Thanks for leaving an update! I switched my setup to avoid this problem, but I'm happy to give this setup a shot again when I have some more time.