Skip to content

[Bug]: py_venv generated by py_binary/py_test ignores python_version #541

Open
@lqc

Description

@lqc

What happened?

Created virtual env points to the default python interpreter instead of the one used by binary.

Version

Development (host) and target OS/architectures: darwin/arm64

Output of bazel --version: aspect 2024.51.11+60ad64d6e

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:

bazel_dep(name = "aspect_bazel_lib", version = "2.11.0")
bazel_dep(name = "rules_python", version = "1.2.0")
bazel_dep(name = "aspect_rules_py", version = "1.3.0")
bazel_dep(name = "rules_uv", version = "0.52.0")

Language(s) and/or frameworks involved:

Python

How to reproduce

MODULE:


python.toolchain(
    is_default = True,
    python_version = "3.10.16",
)
python.toolchain(
    is_default = False,
    python_version = "3.13",
)
use_repo(python)


BUILD:


load("@aspect_rules_py//py:defs.bzl", "py_binary")

py_binary(name = "foo", srcs=["foo.py"], python_version = "3.13")


foo.py


import sys
print(sys.version_info)


1) If you run ``bazel run //:foo``, it prints correctly version 3.13. 

2) Run ``bazel run //:foo.venv`` to create the venv

3) Run ``.foo.venv/bin/python --version``. Expected also 3.13, but for 3.10

Any other information?

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingneed: investigationInvestigation required to proceed further

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions