Skip to content

Issue with Python Version Mismatch in Bazel (rules_python 1.4.1) #3488

@huyhoang8704

Description

@huyhoang8704

🐛 Bug Report: pip.parse ignores specified Python version and uses default toolchain
Environment

rules_python: v1.4.1

Bazel: (please fill in your version if needed)

OS: Linux

Python versions involved: 3.8, 3.10

🧩 Description

I am trying to use multiple Python versions in the same Bazel workspace.

The default Python toolchain is configured as Python 3.10:

python.toolchain(
configure_coverage_tool = True,
is_default = True,
python_version = "3.10.8",
)

At the same time, I want to install dependencies for a different component using Python 3.8, so I configured pip.parse as follows:

pip.parse(
hub_name = "sherlock_all_deps",
python_interpreter_target = python_3_8,
python_version = "3.8",
requirements_lock = "//sherlock/atolibrary:requirements.txt",
)
❌ Observed Behavior

DEBUG:bazel-cache/local/external/rules_python~/python/private/config_settings.bzl:210:14: The current configuration rules_python config flags is:
@@rules_python~//python/config_settings:pip_whl: "auto"
@@rules_python~//python/config_settings:pip_whl_glibc_version: ""
@@rules_python~//python/config_settings:pip_whl_muslc_version: ""
@@rules_python~//python/config_settings:pip_whl_osx_arch: "arch"
@@rules_python~//python/config_settings:pip_whl_osx_version: ""
@@rules_python~//python/config_settings:py_freethreaded: "no"
@@rules_python~//python/config_settings:py_linux_libc: "glibc"
@@rules_python~//python/config_settings:python_version: "3.10.8"

If the value is missing, then the default value is being used, see documentation:
https://rules-python.readthedocs.io/en/latest/api/rules_python/python/config_settings
ERROR: /home/hoangnguyen20/.momo/bazel-cache/local/external/rules_pythonpip~sherlock_all_deps/click/BUILD.bazel:6:12: configurable attribute "actual" in @@rules_pythonpip~sherlock_all_deps//click:_no_matching_repository doesn't match this configuration: No matching wheel for current configuration's Python version.

The current build configuration's Python version doesn't match any of the Python
wheels available for this distribution. This distribution supports the following Python
configuration settings:
//_config:is_cp38_py3_none_any
//_config:is_cp38_sdist

To determine the current configuration's Python version, run:
bazel config <config id> (shown further below)

For the current configuration value see the debug message above that is
printing the current flag values. If you can't see the message, then re-run the
build to make it a failure instead by running the build with:
--@@rules_python~//python/config_settings:current_config=fail

However, the command above will hide the bazel config <config id> message.

This instance of @@rules_python~~pip~sherlock_all_deps//click:_no_matching_repository has configuration identifier 138a18d. To inspect its configuration, run: bazel config 138a18d.

For more help, see https://bazel.build/docs/configurable-attributes#faq-select-choose-condition.

✅ Expected Behavior

pip.parse should respect:

python_version = "3.8"

and resolve dependencies using the Python 3.8 interpreter, independent of the default toolchain.

❓ Questions

Is it supported to use multiple Python versions (e.g. 3.8 and 3.10) within the same Bazel workspace using rules_python?

If yes, what is the correct way to bind pip.parse to a specific Python toolchain?

If not, is the recommended approach to:

use separate workspaces, or

define multiple toolchains and switch via --platforms / --extra_toolchains?

Any guidance or best practices would be greatly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions