I am trying to set up an environment in Visual Studio Code for a Python project using uv on Ubuntu.
I have tried different sequences of actions, but without success. Here is the latest one:
uv init
uv venv
source .venv/bin/activate
uv add numpy pandas statsmodels
uv sync
Which results in this warning and in no packages being installed:
Which is the right way of creating a virtual environment?
How do I best clean up the mess I made so far and reinitialize things correctly?
Here the verbose output:
cd ~/codes/projects/WQU
uv sync --verbose
Output:
DEBUG uv 0.5.26
DEBUG Found project root: `/home/andrea/codes/projects/WQU`
DEBUG Found workspace root: `/home/andrea`
DEBUG Adding root workspace member: `/home/andrea`
DEBUG Adding current workspace member: `/home/andrea/codes/projects/WQU`
DEBUG Adding discovered workspace member: `/home/andrea/codes/tmp`
DEBUG Adding discovered workspace member: `/home/andrea/codes/projects/tests`
DEBUG Reading Python requests from version file at `/home/andrea/.python-version`
DEBUG Using Python request `3.12` from version file at `/home/andrea/.python-version`
warning: `VIRTUAL_ENV=.venv` does not match the project environment path `/home/andrea/.venv` and will be ignored
DEBUG Checking for Python environment at `/home/andrea/.venv`
DEBUG The virtual environment's Python version satisfies `3.12`
DEBUG Using request timeout of 30s
DEBUG Found static `pyproject.toml` for: andrea @ file:///home/andrea
DEBUG Found workspace root: `/home/andrea`
DEBUG Adding current workspace member: `/home/andrea`
DEBUG Adding discovered workspace member: `/home/andrea/codes/tmp`
DEBUG Adding discovered workspace member: `/home/andrea/codes/projects/tests`
DEBUG Adding discovered workspace member: `/home/andrea/codes/projects/WQU`
DEBUG Found static `pyproject.toml` for: tests @ file:///home/andrea/codes/projects/tests
DEBUG Found workspace root: `/home/andrea`
DEBUG Adding root workspace member: `/home/andrea`
DEBUG Adding current workspace member: `/home/andrea/codes/projects/tests`
DEBUG Adding discovered workspace member: `/home/andrea/codes/tmp`
DEBUG Adding discovered workspace member: `/home/andrea/codes/projects/WQU`
DEBUG Found static `pyproject.toml` for: tmp @ file:///home/andrea/codes/tmp
DEBUG Found workspace root: `/home/andrea`
DEBUG Adding root workspace member: `/home/andrea`
DEBUG Adding current workspace member: `/home/andrea/codes/tmp`
DEBUG Adding discovered workspace member: `/home/andrea/codes/projects/tests`
DEBUG Adding discovered workspace member: `/home/andrea/codes/projects/WQU`
DEBUG Found static `pyproject.toml` for: wqu @ file:///home/andrea/codes/projects/WQU
DEBUG Found workspace root: `/home/andrea`
DEBUG Adding root workspace member: `/home/andrea`
DEBUG Adding current workspace member: `/home/andrea/codes/projects/WQU`
DEBUG Adding discovered workspace member: `/home/andrea/codes/tmp`
DEBUG Adding discovered workspace member: `/home/andrea/codes/projects/tests`
DEBUG Existing `uv.lock` satisfies workspace requirements
Resolved 27 packages in 5ms
DEBUG Using request timeout of 30s
DEBUG Requirement already installed: matplotlib==3.10.1
DEBUG Requirement already installed: statsmodels==0.14.4
DEBUG Requirement already installed: contourpy==1.3.2
DEBUG Requirement already installed: cycler==0.12.1
DEBUG Requirement already installed: fonttools==4.57.0
DEBUG Requirement already installed: kiwisolver==1.4.8
DEBUG Requirement already installed: numpy==2.2.5
DEBUG Requirement already installed: packaging==25.0
DEBUG Requirement already installed: pillow==11.2.1
DEBUG Requirement already installed: pyparsing==3.2.3
DEBUG Requirement already installed: python-dateutil==2.9.0.post0
DEBUG Requirement already installed: pandas==2.2.3
DEBUG Requirement already installed: patsy==1.0.1
DEBUG Requirement already installed: scipy==1.15.3
DEBUG Requirement already installed: six==1.17.0
DEBUG Requirement already installed: pytz==2025.2
DEBUG Requirement already installed: tzdata==2025.2
Audited 17 packages in 2ms
But nothing was installed in the virtual environment.
The reason uv did not install packages into .venv was that I had a rogue pyproject.toml file in a parent directory (/home/andrea).
When uv runs, it searches upward for a pyproject.toml file to determine the project root. In my case, I can see in the logs that it picked /home/andrea as the workspace root, leading it to use /home/andrea/.venv instead of the projects' .venv even if I ran uv from the projects' folder*. This caused the warning:
warning: VIRTUAL_ENV=.venv does not match the project environment path /home/andrea/.venv and will be ignored
To fix the problem, I deleted the pyproject.toml file in /home/andrea and recreated the environment just for safety measure:
rm /home/andrea/pyproject.toml
rm -rf .venv
uv venv source .venv/bin/activate uv add statsmodels
Note that you can verify that python points to your local .venv folder:
which python