Summary
I tried changing an existing devcontainer to use uv instead of pip, and I ran into the error mentioned in ##11599.
Initial devcontainer.json with only uv added:
{
"name": "Example",
"image": "mcr.microsoft.com/devcontainers/python:1-3.12-bookworm",
"features": {
"ghcr.io/devcontainers-extra/features/apt-get-packages:1": {},
"ghcr.io/va-h/devcontainers-features/uv:1": {}
},
"postCreateCommand": "pip install -r .devcontainer/requirements.txt",
"customizations": {
"vscode": {
"extensions": [
"ms-toolsai.jupyter",
"charliermarsh.ruff"
]
}
}
}
requirements.txt:
chromadb==0.6.3
ipykernel==6.29.5
ipywidgets==8.1.5
lancedb==0.21.1
polars==1.24.0
sentence-transformers==3.4.1
When I change postCreateCommand to use uv like this "postCreateCommand": "uv pip install -r .devcontainer/requirements.txt", I get this:
Running the postCreateCommand from devcontainer.json...
[4474 ms] Start: Run in container: /bin/sh -c uv pip install -r .devcontainer/requirements.txt
error: No virtual environment found; run `uv venv` to create an environment, or pass `--system` to install into a non-virtual environment
When I then add --system to get "postCreateCommand": "uv pip install --system -r .devcontainer/requirements.txt", I get another error:
Built pypika==0.48.9
Prepared 134 packages in 8.74s
error: Failed to install: websockets-15.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (websockets==15.0.1)
Caused by: failed to create directory `/usr/local/lib/python3.12/site-packages/websockets-15.0.1.dist-info`: Permission denied (os error 13)
Example
Ideally, a user could simply add a uv feature to a devcontainer, change the postCreateCommand to use uv pip instead of pip, and have it work.
More broadly, it would be nice to see worked examples of how uv works nicely with devcontainers. Among other things, I work with beginners (other PhD researchers), and I build a devcontainer for the course I teach (and use them extensively in my own projects, both academic and external). It would be nice to see uv work well throughout the lifecycle of a project:
- Creation. If I'm creating a new devcontainer (e.g., using VSCode "Dev Containers: Add Dev Container Configuration Files..."), how can I do so easily? I usually build the container,
pip install the needed packages, let it solve, pip freeze, and use that output to pin only the versions of the key packages (intended to be a portability habit). Then I rebuild again and work.
- Adding uv to an existing project. Ideally, I could do what I described above, but what's the intended way to do this? I tend to think that it should drop in a replacement for pip and then let folks work from there to use the other features.
- Adding packages. How should we add new packages? (This seems covered in the normal docs.)
- Updating packages. Academic projects often last for years, so there are often package updates that would add something helpful. How can I update packages, test if anything is broken (more like ad hoc experimentation than
pytest), and keep/rollback the update? I usually teach a pip freeze approach, but the docs make it look potentially much easier with uv.
I think it would be great if uv had a devcontainer feature that simply handled all of the venv, --target, and other differences for users. In a devcontainer, there's generally just one Python install that matters, and that's usr/local/bin/python, which I think is the root of a lot of the previous discussion about --user.
Summary
I tried changing an existing devcontainer to use
uvinstead ofpip, and I ran into the error mentioned in ##11599.Initial devcontainer.json with only uv added:
requirements.txt:
When I change
postCreateCommandto use uv like this"postCreateCommand": "uv pip install -r .devcontainer/requirements.txt", I get this:When I then add
--systemto get"postCreateCommand": "uv pip install --system -r .devcontainer/requirements.txt", I get another error:Example
Ideally, a user could simply add a
uvfeature to a devcontainer, change thepostCreateCommandto useuv pipinstead ofpip, and have it work.More broadly, it would be nice to see worked examples of how uv works nicely with devcontainers. Among other things, I work with beginners (other PhD researchers), and I build a devcontainer for the course I teach (and use them extensively in my own projects, both academic and external). It would be nice to see uv work well throughout the lifecycle of a project:
pip installthe needed packages, let it solve,pip freeze, and use that output to pin only the versions of the key packages (intended to be a portability habit). Then I rebuild again and work.pytest), and keep/rollback the update? I usually teach apip freezeapproach, but the docs make it look potentially much easier with uv.I think it would be great if uv had a devcontainer feature that simply handled all of the venv,
--target, and other differences for users. In a devcontainer, there's generally just one Python install that matters, and that'susr/local/bin/python, which I think is the root of a lot of the previous discussion about--user.