I’ve loved uv
‘s local DevEx until now, but I can’t seem to find the “recommended”/”best” way to create a docker image that installs all my dependencies system-wide (without a venv).
I’ve tried with a ‘pyproject.toml’ (and associated ‘uv.lock’):
[project] name = "api" version = "0.1.0" description = "Add your description here" readme = "README.md" requires-python = ">=3.13" dependencies = [ "fastapi>=0.115.6", etc... ] [dependency-groups] dev = [ "pytest>=8.3.4", etc... ]
And a Dockerfile:
FROM ghcr.io/astral-sh/uv:python3.13-alpine #ENV UV_PROJECT_ENVIRONMENT="/usr/local/bin/" TODO ??? ENV PYTHONUNBUFFERED True WORKDIR /app COPY . . RUN uv sync --locked --python-preference system --no-dev
BUT exec’ing into the image after build, I see no ‘.venv/’ and:
/app # python main.py Traceback (most recent call last): File "/app/main.py", line 1, in <module> from fastapi import FastAPI ModuleNotFoundError: No module named 'fastapi'
- Should I be using
uv install --system...
instead or is that deprecated? - Should I use UV_PROJECT_ENVIRONMENT?
- Should I simply run everything within a venv inside containers somehow?
Any help or suggestions is greatly appreciated!!
submitted by /u/ryanstephendavis
[link] [comments]
r/learnpython I’ve loved uv’s local DevEx until now, but I can’t seem to find the “recommended”/”best” way to create a docker image that installs all my dependencies system-wide (without a venv). I’ve tried with a ‘pyproject.toml’ (and associated ‘uv.lock’): [project] name = “api” version = “0.1.0” description = “Add your description here” readme = “README.md” requires-python = “>=3.13” dependencies = [ “fastapi>=0.115.6”, etc… ] [dependency-groups] dev = [ “pytest>=8.3.4″, etc… ] And a Dockerfile: FROM ghcr.io/astral-sh/uv:python3.13-alpine #ENV UV_PROJECT_ENVIRONMENT=”/usr/local/bin/” TODO ??? ENV PYTHONUNBUFFERED True WORKDIR /app COPY . . RUN uv sync –locked –python-preference system –no-dev BUT exec’ing into the image after build, I see no ‘.venv/’ and: /app # python main.py Traceback (most recent call last): File “/app/main.py”, line 1, in <module> from fastapi import FastAPI ModuleNotFoundError: No module named ‘fastapi’ Should I be using uv install –system… instead or is that deprecated? Should I use UV_PROJECT_ENVIRONMENT? Should I simply run everything within a venv inside containers somehow? Any help or suggestions is greatly appreciated!! submitted by /u/ryanstephendavis [link] [comments]
I’ve loved uv
‘s local DevEx until now, but I can’t seem to find the “recommended”/”best” way to create a docker image that installs all my dependencies system-wide (without a venv).
I’ve tried with a ‘pyproject.toml’ (and associated ‘uv.lock’):
[project] name = "api" version = "0.1.0" description = "Add your description here" readme = "README.md" requires-python = ">=3.13" dependencies = [ "fastapi>=0.115.6", etc... ] [dependency-groups] dev = [ "pytest>=8.3.4", etc... ]
And a Dockerfile:
FROM ghcr.io/astral-sh/uv:python3.13-alpine #ENV UV_PROJECT_ENVIRONMENT="/usr/local/bin/" TODO ??? ENV PYTHONUNBUFFERED True WORKDIR /app COPY . . RUN uv sync --locked --python-preference system --no-dev
BUT exec’ing into the image after build, I see no ‘.venv/’ and:
/app # python main.py Traceback (most recent call last): File "/app/main.py", line 1, in <module> from fastapi import FastAPI ModuleNotFoundError: No module named 'fastapi'
- Should I be using
uv install --system...
instead or is that deprecated? - Should I use UV_PROJECT_ENVIRONMENT?
- Should I simply run everything within a venv inside containers somehow?
Any help or suggestions is greatly appreciated!!
submitted by /u/ryanstephendavis
[link] [comments]