Skip to content

uv run repeatedly compiles bytecode with UV_COMPILE_BYTECODE=1 #12202

@mwaskom

Description

@mwaskom

Summary

Starting with uv 0.5.5, uv run will compile bytecode files on every invocation when UV_COMPILE_BYTECODE=1 is set:

$ uv init
Initialized project `pyc-woe`
$ UV_COMPILE_BYTECODE=1 uv run python -c ''
Using CPython 3.13.0
Creating virtual environment at: .venv
Bytecode compiled 1 file in 39ms
$ UV_COMPILE_BYTECODE=1 uv run python -c ''
Bytecode compiled 1 file in 36ms
$ UV_COMPILE_BYTECODE=1 uv run python -c ''
Bytecode compiled 1 file in 35ms```

While not shown here, all packages in the venv get their bytecode recompiled, so this can add a lot of latency for large environments.

My understanding is that UV_COMPILE_BYTECODE should be telling uv to compile bytecode when installing packages:

Equivalent to the --compile-bytecode command-line argument. If set, uv will compile Python source files to bytecode after installation

Instead, it seems to be effectively setting "ignore the pyc cache and recompile on every invocation of uv run". Maybe that's expected on your end, but we found it very surprising.

Note that this behavior was introduced in 0.5.5. I'm guessing it's a result of this PR.

Platform

Linux 5.15.0-101.103.2.1.el9uek.x86_64 x86_64 GNU/Linux

Version

uv 0.6.6 (as mentioned, the behavior was introduced in 0.5.5)

Python version

Python 3.9.18 when making the repro, but it's not Python version dependent

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions