Skip to content

Can't uv run a simple script when Python binary is a symlink with uv 0.5.x #10674

Closed
@gozdal

Description

@gozdal

I ran into a bug with Ubuntu 24, which has (by default) system-wide Python 3.12.
Coincidently I have our own Python 3.12 installed, which is symlinked from /usr/local/bin/python3.12:
$ ls -al /usr/bin/python3.12

-rwxr-xr-x 1 root root 8019136 Nov  6 13:32 /usr/bin/python3.12

$ ls -al /usr/local/bin/python3.12

lrwxrwxrwx 1 root root 39 Nov 27 14:02 /usr/local/bin/python3.12 -> /opt/starfish/python3.12/bin/python3.12

$ which python3.12

/usr/local/bin/python3.12

Now, if I try to run example.py:

# /// script
# requires-python = ">=3.12"
# dependencies = []
# ///

import sys

def main() -> None:
    print(sys.version)


if __name__ == "__main__":
    main()

uv 0.4.30 works:
uv cache clean && ./0.4.30/uv run example.py

Clearing cache at: /home/gozdal/.cache/uv
Removed 47 files (64.9KiB)
Reading inline script metadata from `example.py`
3.12.5 (main, Nov 14 2024, 04:29:17) [GCC 13.2.0]

uv 0.5.0 and 0.5.20 (latest as I am writing this) fail with ModuleNotFoundError:

uv cache clean && ./0.5.0/uv run example.py

Clearing cache at: /home/gozdal/.cache/uv
Removed 26 files (35.2KiB)
Reading inline script metadata from `example.py`
error: Querying Python at `/home/gozdal/.cache/uv/archive-v0/FUbvxrhgdDsOgH-FF1as3/bin/python3` failed with exit status exit status: 1
--- stdout:

--- stderr:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/gozdal/.cache/uv/.tmpXvEd2n/python/get_interpreter_info.py", line 12, in <module>
    import struct
  File "/usr/lib/python3.12/struct.py", line 13, in <module>
    from _struct import *
ModuleNotFoundError: No module named '_struct'
---

uv cache clean && ./0.5.20/uv run example.py

Clearing cache at: /home/gozdal/.cache/uv
Removed 24 files (29.8KiB)
error: Querying Python at `/home/gozdal/.cache/uv/archive-v0/xvAW0xfqtaDWv89Ju96Pb/bin/python3` failed with exit status exit status: 1
--- stdout:

--- stderr:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/gozdal/.cache/uv/.tmpDMAraa/python/get_interpreter_info.py", line 12, in <module>
    import struct
  File "/usr/lib/python3.12/struct.py", line 13, in <module>
    from _struct import *
ModuleNotFoundError: No module named '_struct'
---

If I remove /usr/local/bin from $PATH, it works:
uv cache clean && PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin ./0.5.0/uv run example.py

Clearing cache at: /home/gozdal/.cache/uv
Removed 24 files (29.8KiB)
Reading inline script metadata from `example.py`
3.12.3 (main, Nov  6 2024, 18:32:19) [GCC 13.2.0]

Similarly if I add /opt/starfish/python3.12/bin to PATH:
uv cache clean && PATH=/opt/starfish/python3.12/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin ./0.5.0/uv run example.py

Clearing cache at: /home/gozdal/.cache/uv
Removed 26 files (34.8KiB)
Reading inline script metadata from `example.py`
3.12.5 (main, Nov 14 2024, 04:29:17) [GCC 13.2.0]

So it seems that the problem is /usr/local/bin symlink.

Metadata

Metadata

Assignees

No one assigned

    Labels

    externalThe problem is with another package or dependency (not uv)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions