-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Poetry wants to reinstall every system package to the venv when using virtualenvs.options.system-site-packages #6035
Comments
Using poetry 1.2.0rc1 (EDIT: 1.2.0)
EDIT:
|
Having this same problem, using the v1.2.0 release. In my docker container, I install some system packages, then in my poetry project, I turn on system-site-packages option, and pin the package version in my But when running |
PTAL @radoering -- looks like more fallout from the work on dependency origins (and could be intended behavior that we need to document). |
I wonder if I'd say this poetry/src/poetry/repositories/installed_repository.py Lines 161 to 164 in cf3dcad
|
Yes, looks like I did not find this issue before filing #7234 - apologies. Maybe I can make up for it with another workaround: With a poetry.toml:
Run this:
It seems that pip is smart enough to "see" the already available packages in the system-wide Python site-packages, and skips the redundant build. I would be happy if the poetry installation manager would do the same. |
@neersighted any comment as to why this is not planned ? |
Looks like I got a wire crossed and closed the wrong issue (#7234 is a duplicate). That being said, |
Clearly, system-site-packages is a venv option, not a native option of poetry. That said, poetry uses and supports venv. So when a (power) user wants to make venv use system-site-packages, then poetry should respect this choice - and be happy with the packages seen in the venv - regardless whether found in the venv itself or in the underlying Python’s system-site-packages. Needless to say that poetry should install a package version in venv in case the version does not match. Thanks for reopening this ticket and I hope this can be fixed soon. |
Is this ever going to be fixed? It's been a thorn in my side for using Poetry on a Raspberry Pi, where I often install packages system-wide to avoid needless hours of building. |
Like all bugs: this will not be fixed before someone who cares about it shows up and fixes it. Is that you? |
This changesets adds a getter to `env.virtual_env.VirtualEnv` to check whether it has access to system packages, and overrides the `is_path_relative_to_lib` method to take it into account. This will prevent Poetry from reinstalling system packages in the venv when they are already installed with a compatible version. Fixes: python-poetry#6035 Signed-off-by: Aurélien Bompard <[email protected]>
Hi @abompard, I'm not quite certain that this issue is fixed by #8359. I am using the master branch on poetry and despite having a package installed in my container, I still run into the same issue where poetry reinstalls existing packages, like this: root@a9ea362e494d:/# poetry config virtualenvs.options.system-site-packages true
root@a9ea362e494d:/# cat pyproject.toml
[tool.poetry]
name = "myproject"
version = "0.0.0"
description = "myproject"
authors = ["me"]
license = "MIT"
readme = "README.md"
[build-system]
requires = ["poetry-core>=1.5.0"]
build-backend = "poetry.core.masonry.api"
[tool.poetry.dependencies]
python = ">=3.8.1,<3.11"
toml = { version = "*"}
requests = { version = "*"}
spython = { version = "*"}
typer = {version = "*", extras = ["all"]}
[tool.poetry.group.torch]
optional = true
[tool.poetry.group.torch.dependencies]
torch = {version = ">=2.1.0", source = "torch", allow-prereleases = true}
torchvision = {version = "*", source = "torch", allow-prereleases = true}
torchaudio = {version = "*", source = "torch", allow-prereleases = true}
[[tool.poetry.source]]
name = "torch"
url = "https://download.pytorch.org/whl/cu118"
root@a9ea362e494d:/# poetry install --no-root --only torch --dry-run
Installing dependencies from lock file
Package operations: 0 installs, 19 updates, 0 removals
- Updating filelock (3.9.0 /usr/local/lib/python3.10/dist-packages -> 3.13.1)
- Updating markupsafe (2.1.3 /usr/local/lib/python3.10/dist-packages -> 2.1.3)
- Updating mpmath (1.3.0 /usr/local/lib/python3.10/dist-packages -> 1.3.0)
- Updating certifi (2022.12.7 /usr/local/lib/python3.10/dist-packages -> 2023.11.17)
- Updating charset-normalizer (2.1.1 /usr/local/lib/python3.10/dist-packages -> 3.3.2)
- Updating fsspec (2023.4.0 /usr/local/lib/python3.10/dist-packages -> 2023.10.0)
- Updating idna (3.4 /usr/local/lib/python3.10/dist-packages -> 3.4)
- Updating jinja2 (3.1.2 /usr/local/lib/python3.10/dist-packages -> 3.1.2)
- Updating sympy (1.12 /usr/local/lib/python3.10/dist-packages -> 1.12)
- Updating triton (2.1.0 /usr/local/lib/python3.10/dist-packages -> 2.1.0)
- Updating typing-extensions (4.4.0 /usr/local/lib/python3.10/dist-packages -> 4.4.0)
- Updating urllib3 (1.26.13 /usr/local/lib/python3.10/dist-packages -> 2.1.0)
- Updating networkx (3.0 /usr/local/lib/python3.10/dist-packages -> 3.1)
- Updating numpy (1.24.1 /usr/local/lib/python3.10/dist-packages -> 1.24.4)
- Updating pillow (9.3.0 /usr/local/lib/python3.10/dist-packages -> 10.1.0)
- Updating torch (2.1.1+cu118 /usr/local/lib/python3.10/dist-packages -> 2.1.1+cu118)
- Updating requests (2.28.1 /usr/local/lib/python3.10/dist-packages -> 2.31.0)
- Updating torchaudio (2.1.1+cu118 /usr/local/lib/python3.10/dist-packages -> 2.1.1+cu118)
- Updating torchvision (0.16.1+cu118 /usr/local/lib/python3.10/dist-packages -> 0.16.1+cu118)
root@a9ea362e494d:/# poetry --version
Poetry (version 1.8.0.dev0) Now, I understand that my issue could stem from something different because, well, Pytorch. However, it also happens for Pytorch's dependencies, which is why I wanted to raise this here. If I am misunderstanding something, I would greatly appreciate being pointed in the right direction. Thank you. |
It works for me ( # find / -name 'torch' 2>/dev/null
/usr/local/lib/python3.10/dist-packages/torch My "source" is setup as |
Thanks for testing! Would you mind sharing your pyproject.toml for the pytorch case? I've boiled it down as much as I could and I still cannot get it to work: My source is explicit and no longer part of a dep group. I also set forced it to 2.0.0, in case it was something about how pip installs that version, but no luck. TOML file [tool.poetry]
name = "poetry-torch"
version = "0.0.0"
description = "Testing poetry and torch"
authors = ["Me"]
[build-system]
requires = ["poetry>=1.1"]
build-backend = "poetry.masonry.api"
[tool.poetry.dependencies]
python = ">=3.8.1,<3.11"
torch = {version = "=2.0.0", source = "torch"}
[[tool.poetry.source]]
name = "torch"
priority = "explicit"
url = "https://download.pytorch.org/whl/cu117" Dockerfile # Start from the NVIDIA PyTorch image
FROM nvidia/cuda:11.7.1-runtime-ubuntu22.04
ENV DEBIAN_FRONTEND=noninteractive
# Install required tools and libraries, and clean up to reduce layer size
RUN apt-get update \
&& apt-get install -y software-properties-common \
&& apt-get install -y libstdc++6 libgl1 wget curl git bzip2 python3 python3-pip\
&& apt-get remove --purge -y software-properties-common \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Symlink python
RUN rm -f /usr/bin/python && ln -s /usr/bin/python3 /usr/bin/python
ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache \
POETRY_HOME=/opt/poetry \
POETRY_VIRTUALENVS_OPTIONS_SYSTEM_SITE_PACKAGES=1
RUN --mount=type=cache,target=~/.cache/pip \
pip3 install torch==2.0.0 --index-url https://download.pytorch.org/whl/cu117
# Install poetry with pinned version
RUN curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.7.1 python3 -
ENV PATH="$PATH:$POETRY_HOME/bin"
# Set site packages to be available
# The env vars should have handled this
# But that is currently broken for OPTIONS
RUN poetry config virtualenvs.options.system-site-packages true
COPY poetry.lock pyproject.toml ./ Testing it out: (base) alodie@alodie:~/git/poetry-torch$ docker run -it poetry-torch /bin/bash
==========
== CUDA ==
==========
CUDA Version 11.7.1
Container image Copyright (c) 2016-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
This container image and its contents are governed by the NVIDIA Deep Learning Container License.
By pulling and using the container, you accept the terms and conditions of this license:
https://developer.nvidia.com/ngc/nvidia-deep-learning-container-license
A copy of this license is made available in this container at /NGC-DL-CONTAINER-LICENSE for your convenience.
WARNING: The NVIDIA Driver was not detected. GPU functionality will not be available.
Use the NVIDIA Container Toolkit to start this container with GPU support; see
https://docs.nvidia.com/datacenter/cloud-native/ .
root@43cc2d141b0d:/# poetry --version
Poetry (version 1.7.1)
root@43cc2d141b0d:/# find / -name 'torch' 2>/dev/null
/usr/local/lib/python3.10/dist-packages/torch
/usr/local/lib/python3.10/dist-packages/torch/include/torch
/usr/local/lib/python3.10/dist-packages/torch/include/torch/csrc/api/include/torch
root@43cc2d141b0d:/# poetry install --dry-run
Creating virtualenv poetry-torch in /.venv
Installing dependencies from lock file
Package operations: 0 installs, 11 updates, 0 removals
• Updating cmake (3.25.0 /usr/local/lib/python3.10/dist-packages -> 3.27.7)
• Updating filelock (3.9.0 /usr/local/lib/python3.10/dist-packages -> 3.13.1)
• Updating lit (15.0.7 /usr/local/lib/python3.10/dist-packages -> 17.0.5)
• Updating markupsafe (2.1.3 /usr/local/lib/python3.10/dist-packages -> 2.1.3)
• Updating mpmath (1.3.0 /usr/local/lib/python3.10/dist-packages -> 1.3.0)
• Updating jinja2 (3.1.2 /usr/local/lib/python3.10/dist-packages -> 3.1.2)
• Updating networkx (3.0 /usr/local/lib/python3.10/dist-packages -> 3.1)
• Updating triton (2.0.0 /usr/local/lib/python3.10/dist-packages -> 2.0.0)
• Updating typing-extensions (4.4.0 /usr/local/lib/python3.10/dist-packages -> 4.8.0)
• Updating sympy (1.12 /usr/local/lib/python3.10/dist-packages -> 1.12)
• Updating torch (2.0.0+cu117 /usr/local/lib/python3.10/dist-packages -> 2.0.0+cu117)
Installing the current project: poetry-torch (0.0.0) |
I also have a simple example of this not working in a Docker build: https://github.com/UFO-101/auto-circuit/blob/main/Dockerfile
|
Have been running up against this problem myself, and the most useful workaround I can see for this (or perhaps it is the intended way?) is to define the dependencies that your container provides as an optional group or set of extras, and opt out of it on container builds. Since updating any of these will necessitate using a new base container version, you'll definitely want to pin these to an exact version anyway. For example, this container provides
Use the group outside the container to get all dependencies on your local system venv
Build
Verify that package is already installed correctly
Install without overwriting anything, hooray!
What we're trying to avoid (and what appears to still be buggy behaviour?)
It's a fairly simple and contrived example, so in reality you may need to pin a few more things from your container site-packages into the container extras/group, but a bit of manual solving is fairly inevitable with this kind of "overlay" dependency solution. I'll leave the horrible bash one-liner to pipe the output of |
@birdcolour Thanks for sharing that, and it does help with my use-case too.
|
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
-vvv
option).Issue
When I set
virtualenvs.options.system-site-packages
totrue
, my program running inside the poetry venv has access to the system deps (good). But when I runpoetry install
, poetry wants to re-download and re-install everything (bad).Either I use
virtualenvs.options.system-site-packages true
and poetry should use the system deps (unless not possible, eg not if version mismatch). Or I usevirtualenvs.options.system-site-packages false
and system deps are never used.Currently If I want to use a dependency from the system site-packages I have to remove it from pyproject.toml and poetry.lock before
poetry install
.To reproduce
output is:
Here I use
--dry-run
for the example, but without--dry-run
poetry downloads the packages then installs then to the venv (but I already have these packages ! I don't want to re-download everything !).see #1393 (comment)
The text was updated successfully, but these errors were encountered: