rules_python icon indicating copy to clipboard operation
rules_python copied to clipboard

Unable to find interpreter for pip hub

Open SDAChess opened this issue 10 months ago • 2 comments

🐞 bug report

Affected Rule

Probably a missuse on my end but pip.parse

Is this a regression?

No.

Description

When trying to use rules_python to fetch dependencies from Pypi with Bzlmod I'm running into this error message:

Extracting Bazel installation...
Starting local Bazel server and connecting to it...
ERROR: Traceback (most recent call last):
	File "/home/nvidia/.cache/bazel/_bazel_nvidia/73a3c98af12e8cd8cdc191f6b030862f/external/rules_python~/python/private/bzlmod/pip.bzl", line 355, column 30, in _pip_impl
		_create_whl_repos(module_ctx, pip_attr, hub_whl_map, whl_overrides)
	File "/home/nvidia/.cache/bazel/_bazel_nvidia/73a3c98af12e8cd8cdc191f6b030862f/external/rules_python~/python/private/bzlmod/pip.bzl", line 111, column 17, in _create_whl_repos
		fail((
Error in fail: Unable to find interpreter for pip hub 'deps' for python_version=3.10: Make sure a corresponding `python.toolchain(python_version="3.10")` call exists
ERROR: error evaluating module extension pip in @@rules_python~//python/extensions:pip.bzl
INFO: Elapsed time: 7.249s
INFO: 0 processes.
ERROR: Build did NOT complete successfully
ERROR: Build failed. Not running target
FAILED:
    Fetching module extension pip in @@rules_python~//python/extensions:pip.bzl; starting

🔬 Minimal Reproduction

I am running Bazel into a Docker container which as base image as Ubuntu 22.04.

Dockerfile:

FROM ubuntu:22.04

RUN apt update -y

RUN apt install apt-transport-https curl gnupg -y

RUN curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel-archive-keyring.gpg
RUN mv bazel-archive-keyring.gpg /usr/share/keyrings
RUN echo "deb [arch=amd64 signed-by=/usr/share/keyrings/bazel-archive-keyring.gpg] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list

RUN apt update -y && apt install bazel -y

RUN apt install python3 python3-pip -y

RUN useradd -ms /bin/bash test
USER test
WORKDIR /home/test
COPY . .

MODULE.bzl:

module(
    name = "test",
    version = "0.1.0",
)

bazel_dep(
    name = "rules_python",
    version = "0.31.0",
)

python = use_extension("@rules_python//extensions:python.bzl", "python")
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")

python.toolchain(
    python_version = "3.10",
    is_default = True,
)

pip.parse(
    hub_name = "deps",
    python_version = "3.10",
    requirements_lock = "//:requirements.txt",
)

use_repo(pip, "deps")

requirements.txt:

asyncio

BUILD:

load("@deps//:requirements.bzl", "requirement")

py_binary(
    name = "test",
    srcs = [
        "test.py",
    ],
    deps = [
        requirement("asyncio"),
    ],
    main = "test.py"
)

SDAChess avatar Apr 24 '24 13:04 SDAChess

I'm thinking this is related to Debian disabling global pip install but I want to make sure.

SDAChess avatar Apr 24 '24 13:04 SDAChess

I can't test this at this very moment, but if the following documentation example is correct:

https://github.com/bazelbuild/rules_python/blob/main/examples/pip_parse/MODULE.bazel

It stands out to me that in your code the use_extension takes a different parameter:

python = use_extension("@rules_python//extensions:python.bzl", "python")

While in the example, the following label is being used:

python = use_extension("@rules_python//python/extensions:python.bzl", "python")

pat-jpnk avatar May 06 '24 12:05 pat-jpnk

Closing as it is more of a support question rather than a bug.

aignas avatar May 13 '24 08:05 aignas

If the following is wrong:

python = use_extension("@rules_python//extensions:python.bzl", "python")

...then are the https://rules-python.readthedocs.io/en/stable/toolchains.html#root-modules docs wrong too? Those docs are also missing the initial python/ component before extensions:python.bzl. I followed those docs and hit this issue, which I resolved by adding the missing python/ to the path.

(This actually took a while to debug since the error message did not make it obvious what the problem was.)

jab avatar May 17 '24 16:05 jab