3 ms·
I want to switch to uv from pyenv but one use case that didn't manage to figure out is if I can have similar setup like pyenv that I install few python version
by pzo 2y ago
I want to switch to uv from pyenv but one use case that didn't manage to figure out is if I can have similar setup like pyenv that I install few python version and setup one to be a global default (configured in zsh). I know for bigger projects proper way is to setup virtual environment for all new project but I do many mini (throwaway) python scripts and experiments or testing repos in python and would be really annoying to setup environment for those - so far pyenv worked well for me for such cases without having pretty much dependency conflicts.
- js2 2y agoYes, uv is well suited to that use case by declaring your Python version and/or dependencies right in the script itself: https://docs.astral.sh/uv/guides/scripts/#declaring-script-dependencies https://docs.astral.sh/uv/guides/scripts/#declaring-script-d... You can use an alternate shebang line so you can run the script directly: #!/usr/bin/env -S uv run --script # /// script # requires-python = ">=3.12" # dependencies = [ # "requests", # "typer-slim", # ] # /// import requests import typer # ...
- pzo 2y agoYes but I then still then have to declare all dependencies for all tiny throwaway script, right now I have global python in pyenv and installed tons of plugins and didn't have too much issues with conflicts so was good enough for me
- biorach 2y agoHow about just install a python version with uv and install everything into that? Or better, do the above, then create a virtual env, set the virtual env in your.bashrc and install everything into that Better still... use uv script --init See other comments on this post
- jsmeaton 2y agoI used to have the same setup - a global tools venv with some useful dependencies. Uv takes the position that since it’s so fast to install dependencies and create environments, you don’t maintain a global venv. uvx ruff file.py Will setup a venv, install ruff into it, and run over your file. https://docs.astral.sh/uv/guides/tools/ https://docs.astral.sh/uv/guides/tools/ Otherwise you can: uv run —-with package file.py If you don’t want to declare your dependencies. https://docs.astral.sh/uv/guides/scripts/#running-a-script-with-dependencies https://docs.astral.sh/uv/guides/scripts/#running-a-script-w...
- sorenjan 2y agoYou could make an alias for creating a new python script that adds your favorite libraries as dependencies: alias newpy='function _newpy() { default_deps=("rich" "requests"); uv init --script "$1" && uv add "${default_deps[@]}" --script "$1"; }; _newpy'