pythonuv

python uv module : confusing behaviour


I started to consider using uv for my project instead for pip. However, so far I am finding using it not as straightforward as I'd hoped.

EDIT: OS Windows 10, Python 3.10 installed from Windows Store.

  1. uv is not added to PATH variable (I did not have this issue in my initial testing, but now I do. Restart does not help)
  2. Confusing behavior with VENV created by uv
mkdir uvtest
cd uvtest
python -m uv init
python -m uv venv
.venv\Scripts\activate
python -m uv help REM .venv\Scripts\python.exe: No module named uv
pip install uv REM Requirement already satisfied: uv in c:\users\sergz\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (0.5.13)```

Solution

  • A few things to note:

    The workflow should thus look like this:

    $ uv init uvtest && cd uvtest
    Initialized project `uvtest` at `~\uvtest`
    
    $ uv venv
    Using CPython 3.13.0
    Creating virtual environment at: .venv
    Activate with: .venv\Scripts\activate
    
    # https://docs.astral.sh/uv/concepts/projects/dependencies/
    $ uv add some-dependency
    Resolved 1 packages in 3.14ms
    Prepared 1 package in 6.28ms
    Installed 1 package in 2.72ms
     + some-dependency==1.2.3
    
    # https://docs.astral.sh/uv/concepts/projects/run/
    $ uv run some-tool --version
    4.5.6
    

    (uv venv is actually unnecessary if you don't use an IDE that relies on virtual environments. Other commands like uv run will create an environment if there isn't one already.)