astral-sh / rye

a Hassle-Free Python Experience
https://rye.astral.sh
MIT License
13.6k stars 466 forks source link

Unable to install langchain #1145

Closed dennisrall closed 2 months ago

dennisrall commented 3 months ago

Steps to Reproduce

  1. Create a new rye project mkdir test, cd test, rye init
  2. Add langchain rye add langchain

Expected Result

Langchain should be added to the project and the log files should be created correctly.

Creating a virtualenv and installing langchain with venv, poetry and uv works. So it has something to do with rye, but I don't know what😅

Actual Result

Initializing new virtualenv in /home/dennis/Projects/test/.venv
Python version: cpython@3.12.3
Added langchain>=0.2.3 as regular dependency
Reusing already existing virtualenv
Generating production lockfile: /home/dennis/Projects/test/requirements.lock
  × No solution found when resolving dependencies:
  ╰─▶ Because only the following versions of packaging are available:
          packaging<23.2
          packaging>=24.0
      and any of:
          langchain-core>=0.2.0,<=0.2.1
          langchain-core>=0.2.2
      depends on packaging>=23.2,<24.0, we can conclude that any of:
          langchain-core>=0.2.0,<=0.2.1
          langchain-core>=0.2.2
       cannot be used.
      And because only the following versions of langchain-core are available:
          langchain-core<=0.2.1
          langchain-core>=0.2.2
      and langchain==0.2.3 depends on langchain-core>=0.2.0, we can conclude that langchain==0.2.3 cannot be used.
      And because only langchain<=0.2.3 is available and you require langchain>=0.2.3, we can conclude that the requirements are unsatisfiable.

      hint: Pre-releases are available for langchain-core in the requested range (e.g., 0.2.2rc1), but pre-releases weren't enabled (try: `--prerelease=allow`)
error: could not write production lockfile for project

Caused by:
    Failed to run uv compile /tmp/.tmp0AN7u3/requirements.txt. uv exited with status: exit status: 1

Version Info

rye 0.34.0
commit: 0.34.0 (d31340178 2024-05-20)
platform: linux (x86_64)
self-python: cpython@3.12.3
symlink support: true
uv enabled: true

Stacktrace

No response

charliermarsh commented 3 months ago

Do you see the same result if you run uv cache clean first? I can't reproduce this, trying to understand why packaging==23.2 isn't being considered.

dennisrall commented 3 months ago

Yes, same result. I think I also cleared the cache during my troubleshooting, but I checked again and I get the same error.

charliermarsh commented 3 months ago

Do you have anything else in your pyproject.toml or existing lockfile?

dennisrall commented 3 months ago

No the lockfiles do no exist and yet and the pyproject.toml only contains lanchain as a dependency as it is created from the steps to reproduce as described above. Here is the content:

[project]
name = "test"
version = "0.1.0"
description = "Add your description here"
authors = [
    { name = "Dennis Rall", email = "dennis.rall@web.de" }
]
dependencies = [
    "langchain>=0.2.3",
]
readme = "README.md"
requires-python = ">= 3.8"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.rye]
managed = true
dev-dependencies = []

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.build.targets.wheel]
packages = ["src/test"]
bossjones commented 3 months ago

I wonder if you try adding the following? That's how I got things working for my lab project https://github.com/bossjones/goob_ai/blob/main/pyproject.toml#L137 You can see the lockfile as well: https://github.com/bossjones/goob_ai/blob/main/requirements.lock#L373

[build-system]
requires = ["hatchling", "packaging<24"]
build-backend = "hatchling.build"
dennisrall commented 3 months ago

I added it, but I get still the same error

dennisrall commented 3 months ago

I am playing around with some Dockerfiles at the moment, but there I am struggling to reproduce the error...

charliermarsh commented 3 months ago

Thanks, if you can get a repro in a Dockerfile I would love to help fix it.

dennisrall commented 3 months ago

While still trying things out, I found another strange package. Installing predibase locally with rye resolves in an error resolving the dependencies, installing it in a docker container with rye and in an uv managed venv it errors because of the installation of the geventhttpclient.tests package and adding it with poetry and a pip works totally fine.

Here is the error about resolving the dependencies:

Added predibase>=2024.6.5 as regular dependency
Reusing already existing virtualenv
Generating production lockfile: /home/dennis/Projects/predi-rye/requirements.lock
  × No solution found when resolving dependencies:
  ╰─▶ Because there is no version of urllib3==1.26.12 and predibase==2024.6.5 depends on urllib3==1.26.12, we can conclude that predibase==2024.6.5 cannot be used.
      And because only predibase<=2024.6.5 is available and you require predibase>=2024.6.5, we can conclude that the requirements are unsatisfiable.
error: could not write production lockfile for project

Caused by:
    Failed to run uv compile /tmp/.tmpqBn2cS/requirements.txt. uv exited with status: exit status: 1

The setup is the same as above. A fresh new rye project and predibase is the only dependency.

I guess the issue with with resolving the dependencies is the same as with langchain and the installation error in docker and with uv is an uv bug?

Can you confirm that installing predibase with rye and uv fails on your machine too? And does the second log failing to resolve the depencies provide any other information to you?

charliermarsh commented 3 months ago

Unfortunately it works just fine for me with both Rye and uv on its own (echo "predibase>=2024.6.5" | uv pip compile -), with the exception that I'm on macOS and it tries to build something from source when syncing. But the resolution does include urllib3==1.26.12 as expected.

Kydlaw commented 3 months ago

I am facing the exact same issue as well. Both on Windows 11 and WSL. I'll try to get a DockerFile running as well.

Windows 11 config

rye 0.35.0
commit: 0.35.0 (a1dbc56d4 2024-06-24)
platform: windows (x86_64)
self-python: cpython@3.12.2
symlink support: true
uv enabled: true

WSL Ubuntu 24.04 config

rye 0.33.0
commit: 0.33.0 (58523f69f 2024-04-24)
platform: linux (x86_64)
self-python: cpython@3.12.3
symlink support: true
uv enabled: true
charliermarsh commented 3 months ago

Thanks, I am happy to take a look at anything that I can repro!

dennisrall commented 2 months ago

Finally, I was able to reproduce it consistently.

Seems like there is a problem when you create the config.toml as suggested here in the FAQs.

This is the Dockerfile to reproduce:

FROM ubuntu:latest
RUN apt-get update && apt-get install -y curl
ENV PATH="/root/.rye/shims:$PATH"
RUN curl -sSf https://rye.astral.sh/get | RYE_INSTALL_OPTION="--yes" bash
RUN echo '[[sources]]\nname = "pytorch"\nurl = "https://download.pytorch.org/whl/cpu"' > /root/.rye/config.toml
RUN mkdir test
RUN cd test
RUN rye init
RUN rye add langchain

If you delete the line with the echo to the config.toml if works fine, but when it is enabled it fails.

@Kydlaw Have you also added the pytorch sources to your config.toml?

charliermarsh commented 2 months ago

Ohh, my guess is that packaging exists in the PyTorch index but not at the version you need to resolve LangChain?

charliermarsh commented 2 months ago

You could set UV_INDEX_STRATEGY=unsafe-first-match:

FROM ubuntu:latest
RUN apt-get update && apt-get install -y curl
ENV PATH="/root/.rye/shims:$PATH"
RUN curl -sSf https://rye.astral.sh/get | RYE_INSTALL_OPTION="--yes" bash
RUN echo '[[sources]]\nname = "pytorch"\nurl = "https://download.pytorch.org/whl/cpu"' > /root/.rye/config.toml
RUN mkdir test
RUN cd test
RUN rye init
ENV UV_INDEX_STRATEGY=unsafe-first-match
RUN rye add langchain
charliermarsh commented 2 months ago

The docs on this are here: https://github.com/astral-sh/uv/blob/main/PIP_COMPATIBILITY.md#packages-that-exist-on-multiple-indexes

dennisrall commented 2 months ago

Thanks for the fast response. This fixes my problem. If you like you can merge the PR where I added this as a hint to the docs.