I went to my project directory and ran
uv init
thinking that this would create a default virtual environment. It did not. I added in a few dozen dependencies now appearing in file myproject.toml. But now I want to make this environment available outside uv. For example, I want to run
uvicorn myserver.py
Because I cannot of course run uvicorn uv run myserver.py
.
So to me the documents are not clear in uv about what the baseline is when doing
uv venv
I really need to know if it starts from the project's myproject.toml or something else. Will it start from scratch and ignore myproject.toml? Overwrite myproject.toml, etc.?
Please clarify. If it does start from scratch and ignore myproject.toml, is there a way to initialise a venv environment with the myproject.toml contents?
Will running uv sync actually create the .venv? I only did uv init in the project directory initially. So far its not creating the .venv directory.
I assume you mean pyproject.toml
.
I really need to know if it starts from the projects myproject.toml Or something else. Will it start from scratch and ignore myproject.toml?
uv venv
creates a blank virtualenv – the only packages it installs are seed packages like pip
, when so directed (--seed
).
You don't generally need to explicitly do that, since uv
works with the convention that a .venv
directory in your project directory is the project's virtualenv.
overwrite myproject.toml, etc.?
No, uv venv
doesn't touch your pyproject.toml file.
If it does start from scratch and ignore myproject.toml is there anyway to initialise a venv environent with myproject.toml contents?
uv sync
will ensure the project's virtualenv is up to date (creating one if needed). (If you don't have a virtualenv at .venv
, and want one to be created and your project's packages installed there, just uv sync
.)
Even more helpfully, uv run ...
will run a command with the project's virtualenv activated, syncing it beforehand by default.
In other words, uv init
(once), uv add
(when adding deps), uv run uvicorn myserver.py
are all you need in the basic case:
/v/f/n/6/T/tmp.l8JyBCoDzR $ uv init
Initialized project `tmp-l8jybcodzr`
$ uv add uvicorn fastapi[standard]
Using CPython 3.13.2 interpreter at: /opt/homebrew/opt/python@3.13/bin/python3.13
Creating virtual environment at: .venv
Installed 34 packages in 89ms
/v/f/n/6/T/tmp.l8JyBCoDzR (master) $ uv run uvicorn
Usage: uvicorn [OPTIONS] APP
Try 'uvicorn --help' for help.
...