uv: uv tool run is giving "SyntaxError: Non-UTF-8 code starting with '\xe8' in file..."
Question
Whenever I try to run a tool via uvx (or uv tool run) I get an error:
❯ uvx nox --help
File "C:\Users\Gustav\AppData\Local\uv\cache\archive-v0\WSO8dwyzdXet_5ZRAQqqx\Scripts\nox.exe", line 1
SyntaxError: Non-UTF-8 code starting with '\xe8' in file C:\Users\Gustav\AppData\Local\uv\cache\archive-v0\WSO8dwyzdXet_5ZRAQqqx\Scripts\nox.exe on line 2, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
This is happening for (as far as I can see) every tool, and with older versions of uv as well as the current version. I’ve tested with uv 0.6.5, 0.6.4 and 0.5.30. It doesn’t happen with pipx run, and it happens with multiple tools (I’ve tried nox, pdm, and pip) and which suggests that it’s something specifically affecting uv.
I’m pretty sure I’ve used uvx before without this error, so while it’s likely to be something on my machine that is wrong, I don’t know how to diagnose (or fix) the issue. If you can suggest any ways I can work out what’s happening, I’d appreciate it.
I’m running Windows 11, with Powershell Core 7.5 as my shell, and Python 3.13 as my default Python interpreter.
Platform
No response
Version
No response
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 1
- Comments: 20 (15 by maintainers)
PEP 514 support is implemented, it’s still in preview though (
--previeworUV_PREVIEW=1): https://github.com/astral-sh/uv/pull/10634If you do
uv python install 3.7and had previously doneuv python install 3.13, yes we’ll prefer the existing 3.13 install. We use the latest installed managed Python interpreter by default. My sentiment there is less that “I expect a specific Python interpreter to be used after it is installed” and more that “If I install a Python interpreter with uv, I expect uv to use it”. For example, beginners may useuv python installwithout requesting a specific version.I agree, this is what I suggested we should change (and we happen to be doing some related work that will enable this functionality). It might need to be deferred to a breaking release, I’m not sure yet. I think we could consider it a bug fix, but we usually err on the side of marking these as breaking out of an abundance of caution. I’m certain it will break someone’s code .
I’m not confusing them. I am very well aware of the difference. However, I am saying that it is a very unintuitive behaviour to prefer an older version of Python over a newer one based purely on how it was installed. I think it’s problematic enough to be called a bug (and from his response I thought @charliermarsh agreed). But if it’s not, I’m happy to raise it as an enhancement request to get it changed.
For an example of why the current behaviour is bad, consider a new user who has installed Python 3.13 from python.org. They have heard that uv is awesome, and use it to create virtual environments. One day, they find out about
uv runand run a script from a colleague using it. Suddenly, their virtual environments start getting created with a weird older version of Python than 3.13, which is (in their mind) what they have installed. What happened? Answer - the script required Python 3.9, and running it changed the Python version that uv preferred, silently and globally. Sure, the user can set the uv environment variable to use 3.13, but then, when they upgrade Python, everything breaks again.Here you go - it does look like it searched for “managed installations” first, and gave up once it found one, without looking at the registry for later versions.