I'm running into a problem trying to use uv run
with Python's os.exec
variants. Any advice on how to get this to work?
Bash, Ubuntu WSL, uv run python
, execlp
, uv 0.6.5
:
$ uv run python
Python 3.12.9 (main, Feb 12 2025, 14:50:50) [Clang 19.1.6 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.execlp("uv", "run", "python")
Manage Python versions and installations
Usage: run python [OPTIONS] <COMMAND>
(rest of the help text here)
Powershell, Windows 11, uv run main.py
, execv
, uv 0.6.10 (f2a2d982b 2025-03-25)
:
PS > uv run python
Python 3.12.9 (main, Mar 17 2025, 21:06:20) [MSC v.1943 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.execv(r"C:\Users\username\.local\bin\uv.exe", ["run", "main.py"])
PS > error: unrecognized subcommand 'main.py'
Usage: run [OPTIONS] <COMMAND>
I'm running into a problem trying to use uv run
with Python's os.exec
variants. Any advice on how to get this to work?
Bash, Ubuntu WSL, uv run python
, execlp
, uv 0.6.5
:
$ uv run python
Python 3.12.9 (main, Feb 12 2025, 14:50:50) [Clang 19.1.6 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.execlp("uv", "run", "python")
Manage Python versions and installations
Usage: run python [OPTIONS] <COMMAND>
(rest of the help text here)
Powershell, Windows 11, uv run main.py
, execv
, uv 0.6.10 (f2a2d982b 2025-03-25)
:
PS > uv run python
Python 3.12.9 (main, Mar 17 2025, 21:06:20) [MSC v.1943 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.execv(r"C:\Users\username\.local\bin\uv.exe", ["run", "main.py"])
PS > error: unrecognized subcommand 'main.py'
Usage: run [OPTIONS] <COMMAND>
Share
Improve this question
edited Mar 29 at 17:56
InSync
11.1k4 gold badges18 silver badges56 bronze badges
asked Mar 29 at 17:38
agfagf
177k45 gold badges299 silver badges241 bronze badges
0
1 Answer
Reset to default 2Nothing about this is specific to uv, or even to Python: All exec-family calls (including at the C level) allow an argv[0]
to be passed describing to the program that is invoked what name it was started under, allowing programs to have distinct behavior depending on the name they're started with.
The documented signature for execlp looks like os.execlp(file, arg0, arg1, ...)
-- that arg0
is the name the executable is called with, distinct from the file
used to invoke it. Similarly, os.execv(path, args)
assumes that args
will start with an argv[0]
that describes the name the executable was called as, distinct from the filename that resolved to.
In both the examples given here, you're leaving out argv[0]
. Corrected, your calls would look more like:
os.execlp("uv", "uv", "run", "python")
or
os.execv(r"C:\Users\username\.local\bin\uv.exe", ["uv", "run", "main.py"])