Scripting with uv
If you want to do some scripting in Python and have to use a dependency, we have the traditional methods of:
-
Running
pip install pandas
, potentially modifying your global environment. -
Taking the proper route:
- Create a virtual environment
- Activate the virtual environment
pip install pandas
- Run python
And if you have to use a Python version other than the global one, you end up using pyenv
, install the version and set that version as local.
So, worst case:
-
pyenv install 3.12
. -
pyenv local 3.12
. -
python -m venv .venv
. -
source .venv/bin/activate
. -
pip install pandas
. -
python
.
With uv
, it’s just 1 command:
uv run --python 3.12 --with pandas python