News for hackers. Stuff that matters.
Re:uv Running a Script with Dependencies by Hackbraten on Tuesday July 22, 2025 @02:46AM (#44643880)
I wish there was a straightforward way to let VS Code pick up the venv that uv transparently creates.

Out of the box, the Python extension redlines all the third-party imports.

As a workaround, I have to plunge into the guts of uv's Cache directory to tell VS Code the cached venv path manually, and cross fingers that it won't recreate that venv too often.

Re:uv Running a Script with Dependencies by nsarrazin on Tuesday July 22, 2025 @03:18AM (#44644081)
You can find the env path with `uv python find --script "${filePath}`

I've been working on a VSCode extension to automatically detect and activate the right interpreter: https://marketplace.visualstudio.com/items?itemName=nsarrazi...

Re:uv Running a Script with Dependencies by ebri on Tuesday July 22, 2025 @10:16AM (#44647181)
Could you tell me how you do this in code ? Started using uv in a very old school team and they don’t like uv simply because it’s new. Something like this is what they base it on.
Re:uv Running a Script with Dependencies by Hackbraten on Tuesday July 22, 2025 @12:31PM (#44649498)
It's super cumbersome so I can't really recommend it for work.

I invoke the "Select Interpreter" action. A file selector opens, then I go to the user cache directory (e.g. ~/.cache on Linux, something like %LOCALAPPDATA%\Cache on Windows). It has a `uv` subdirectory, then I drill further down until I find the directory where uv keeps its venvs. Find the venv that corresponds to your script, then go to its `bin` subdirectory and select the Python executable.

The upside is that you only have to do this once per script.

The downside is that you have to do this once per script.

Re:uv Running a Script with Dependencies by jjfoooo4 on Tuesday July 22, 2025 @10:42AM (#44647525)
I also just activate the desired virtual env and start VS Code from the command line within it