Basix, ufl and ffcx not found on docker image dolfinx_mpc:v0.10.0

I’ve been messing around all day to get the docker image of dolfinx_mpc:v0.10.0 to work but so far without luck.

Currently my Dockerfile is:

FROM ghcr.io/jorgensd/dolfinx_mpc:v0.10.0
#FROM dolfinx/dev-env:v0.10.0

# Install curl and ca-certificates
RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates

# Download and install UV
ADD https://astral.sh/uv/install.sh /uv-installer.sh
RUN sh /uv-installer.sh && rm /uv-installer.sh
ENV PATH="/root/.local/bin/:$PATH"

# Install GraphViz
RUN apt-get install graphviz

# Set working directory
WORKDIR /workspace

# Copy project metadata
COPY pyproject.toml .
COPY uv.lock .

# Install packages in virtual environment
ENV UV_ENV="/dolfinx-env"        
ENV UV_NO_VENV=1                  
RUN uv sync --all-extras --active

Whenever I try to run any simple code which uses dolfinx, I run into the issue that basix, ufl, and ffcx are not installed on the container. Installing them via UV (or pip) creates new issues and I’m fairly sure this is not needed.

Could anyone shed some light on what I am doing wrong?

import dolfinx.fem
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/dolfinx-real/lib/python3.12/dist-packages/dolfinx/__init__.py", line 32, in <module>
    from dolfinx import fem, geometry, graph, io, jit, la, log, mesh, nls, plot
  File "/usr/local/dolfinx-real/lib/python3.12/dist-packages/dolfinx/fem/__init__.py", line 23, in <module>
    from dolfinx.fem.assemble import (
  File "/usr/local/dolfinx-real/lib/python3.12/dist-packages/dolfinx/fem/assemble.py", line 24, in <module>
    from dolfinx.fem.bcs import DirichletBC
  File "/usr/local/dolfinx-real/lib/python3.12/dist-packages/dolfinx/fem/bcs.py", line 20, in <module>
    from dolfinx.fem.function import Constant, Function, FunctionSpace
  File "/usr/local/dolfinx-real/lib/python3.12/dist-packages/dolfinx/fem/function.py", line 18, in <module>
    import basix
ModuleNotFoundError: No module named 'basix'

This surely has to do with your uv setup, as removing the last lines of your dockerfile and running:



FROM ghcr.io/jorgensd/dolfinx_mpc:v0.10.0
#FROM dolfinx/dev-env:v0.10.0

# Install curl and ca-certificates
RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates

# Download and install UV
ADD https://astral.sh/uv/install.sh /uv-installer.sh
RUN sh /uv-installer.sh && rm /uv-installer.sh
ENV PATH="/root/.local/bin/:$PATH"

# Install GraphViz
RUN apt-get install graphviz

# Set working directory
WORKDIR /workspace

works fine, i.e. python3 -c "import dolfinx; import basix" works.

Further, if you run:

python3 -c "import dolfinx; print(dolfinx); import dolfinx_mpc; print(dolfinx_mpc); import basix; print(basix); import ufl; print(ufl)"

you’ll get

<module 'dolfinx' from '/usr/local/dolfinx-real/lib/python3.12/dist-packages/dolfinx/__init__.py'>
<module 'dolfinx_mpc' from '/usr/local/dolfinx-real/lib/python3.12/dist-packages/dolfinx_mpc/__init__.py'>
<module 'basix' from '/dolfinx-env/lib/python3.12/site-packages/basix/__init__.py'>
<module 'ufl' from '/dolfinx-env/lib/python3.12/site-packages/ufl/__init__.py'>

which points you to the locations where the packages are installed.

I am not sure why youo set UV_ENV adnd UV_NO_VENV, as it seems like just using the already set VIRTUAL_ENV variable it should install packages in the right place.
For instance:

FROM ghcr.io/jorgensd/dolfinx_mpc:v0.10.0
#FROM dolfinx/dev-env:v0.10.0

# Install curl and ca-certificates
RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates

# Download and install UV
ADD https://astral.sh/uv/install.sh /uv-installer.sh
RUN sh /uv-installer.sh && rm /uv-installer.sh
ENV PATH="/root/.local/bin/:$PATH"

# Install GraphViz
RUN apt-get install graphviz

# Set working directory
WORKDIR /workspace

RUN uv pip install pyvista

works and install pyvista, while still being able to import dolfinx, basix, ufl etc.

Alright, well that solves it. Thanks!