Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UV Python Packing: How to set environment variables in virtual envrionments [closed]

Tags:

python

uv

How do I set environment variables in virtual environment creating by UV? I try setting it in .venv/scripts/activate_this.py and it doesn't work.

like image 743
Michael Xia Avatar asked Oct 23 '25 15:10

Michael Xia


1 Answers

You can tell the uv run command to load environment variables from a file, either by using the --env-file option:

uv run --env-file=.env myscript.py

Or by setting the UV_ENV_FILE environment variable:

export UV_ENV_FILE=.env
uv run myscript.py

You will find more details in the documentation.

like image 117
larsks Avatar answered Oct 26 '25 17:10

larsks