The "declaring script dependencies" thing is incredibly useful: https://docs.astral.sh/uv/guides/scripts/#declaring-script-d... # /// script # dependencies = [ # "requests Save that as script.py and you can use "uv run script.py" to run it with the specified dependencies, magically installed into a temporary virtual environment without you having to think about them at all. It's an implementation of Python PEP 723: h…
> Save that as script.py and you can use "uv run script.py" to run it with the specified dependencies, Be aware that uv will create a full copy of that environment for each script by default. Depending on your number of scripts, this could become wasteful really fast. There is a flag "--link-mode symlink" which will link the dependencies from the cache. I'm not sure why this isn't the default, or which disadvantages…
Uv: Running a script with dependencies
131–140 of 174 posts
Re: Uv: Running a script with dependencies
#132I 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.
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.
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
#133Earlier quoted context omitted.
> Save that as script.py and you can use "uv run script.py" to run it with the specified dependencies, Be aware that uv will create a full copy of that environment for each script by default. Depending on your number of scripts, this could become wasteful really fast. There is a flag "--link-mode symlink" which will link the dependencies from the cache. I'm not sure why this isn't the default, or which disadvantages…
By default it will create hard links for python packages, so it won't consume any more memory (besides the small overhead of hard links).
Re: Uv: Running a script with dependencies
#134Earlier quoted context omitted.
uv is so cool. haha. goodbye conda.
conda is a completely no-go for me. It’s for data scientists, and only data scientists who do not need to care much about production.
Re: Uv: Running a script with dependencies
#135Earlier quoted context omitted.
I had the same sentiment, but uv seems to have eliminated the competition. Installing uv using your OS package manager is enough as it can also download and install (isolated) Python interpreters as well.
Except pip still exists and is default, and even if they adopted uv as default instead, all the legacy stuff takes years to change.
Re: Uv: Running a script with dependencies
#136Earlier quoted context omitted.
Note that it's not really "cleaned up" insofar as there is a uv cache folder that will grow bigger over time as you keep using that feature.
True. It's a good idea to periodically run: uv cache clean Or, if you want to specifically clean just jupyter: uv cache clean jupyter
% cd $(uv cache dir); find . -type f | wc -l; du -hs .
234495
16G .Re: Uv: Running a script with dependencies
#137Earlier quoted context omitted.
Except pip still exists and is default, and even if they adopted uv as default instead, all the legacy stuff takes years to change.
pip is not a package manager, it's only meant for installing packages. Also, uv has a pip-compliant interface through `uv pip` which lets you interface with pip easily.
Re: Uv: Running a script with dependencies
#138Earlier quoted context omitted.
pip is not a package manager, it's only meant for installing packages. Also, uv has a pip-compliant interface through `uv pip` which lets you interface with pip easily.
Those shouldn't be separate things. uv is both. Anyway, the default package manager is pipenv https://packaging.python.org/en/latest/tutorials/managing-de...
Re: Uv: Running a script with dependencies
#139The "declaring script dependencies" thing is incredibly useful: https://docs.astral.sh/uv/guides/scripts/#declaring-script-d... # /// script # dependencies = [ # "requests Save that as script.py and you can use "uv run script.py" to run it with the specified dependencies, magically installed into a temporary virtual environment without you having to think about them at all. It's an implementation of Python PEP 723: h…
PEP723 is also supported by pipx and hatch, even though uv is (deservedly) getting all the attention these days. Others like pip-tools have support in the roadmap ( https://github.com/jazzband/pip-tools/issues/2027 )
Re: Uv: Running a script with dependencies
#140Earlier quoted context omitted.
By default it will create hard links for python packages, so it won't consume any more memory (besides the small overhead of hard links).
Unless it can't because you happen to have mounted your user cache directory from a different volume in an attempt to debloat your hourly backups.