FEniCS/basix

Editable install of Python interface broken

Closed this issue · 3 comments

Using the following dockerfile

FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive
ARG TARGET_PLATFORM
RUN apt-get update && \
    apt-get install -y software-properties-common
RUN apt-get install -y git \
    cmake \
    gcc \
    g++ \
    ninja-build \
    libopenblas-dev \ 
    liblapack-dev

RUN apt-get install -y python3-pip
RUN python3 -m pip install -U setuptools pip
RUN python3 -m pip install git+https://github.com/FEniCS/ufl.git

ENV CMAKE_BUILD_PARALLEL_LEVEL 2
WORKDIR /src
RUN git clone https://github.com/FEniCS/basix.git
RUN cd basix && \
    cmake -G Ninja -B build-dir -DCMAKE_BUILD_TYPE=Debug -S cpp/ && \
    cmake --build build-dir && \ 
    cmake --install build-dir


RUN cd basix/python && \
    python3 -m pip install -e . -v


WORKDIR /tmp
RUN python3 -c "import basix"

results in

#15 [12/12] RUN python3 -c "import basix"
#15 0.369 <frozen importlib._bootstrap>:241: RuntimeWarning: nanobind: type 'LatticeType' was already registered!
#15 0.369 
#15 0.369 <frozen importlib._bootstrap>:241: RuntimeWarning: nanobind: type 'LatticeSimplexMethod' was already registered!
#15 0.369 
#15 0.369 <frozen importlib._bootstrap>:241: RuntimeWarning: nanobind: type 'PolynomialType' was already registered!
#15 0.369 
#15 0.369 <frozen importlib._bootstrap>:241: RuntimeWarning: nanobind: type 'MapType' was already registered!
#15 0.369 
#15 0.369 <frozen importlib._bootstrap>:241: RuntimeWarning: nanobind: type 'SobolevSpace' was already registered!
#15 0.369 
#15 0.369 <frozen importlib._bootstrap>:241: RuntimeWarning: nanobind: type 'QuadratureType' was already registered!
#15 0.369 
#15 0.370 <frozen importlib._bootstrap>:241: RuntimeWarning: nanobind: type 'CellType' was already registered!
#15 0.370 
#15 0.370 <frozen importlib._bootstrap>:241: RuntimeWarning: nanobind: type 'ElementFamily' was already registered!
#15 0.370 
#15 0.370 <frozen importlib._bootstrap>:241: RuntimeWarning: nanobind: type 'FiniteElement' was already registered!
#15 0.370 
#15 0.370 <frozen importlib._bootstrap>:241: RuntimeWarning: nanobind: type 'LagrangeVariant' was already registered!
#15 0.370 
#15 0.370 <frozen importlib._bootstrap>:241: RuntimeWarning: nanobind: type 'DPCVariant' was already registered!
#15 0.370 
#15 0.370 <frozen importlib._bootstrap>:241: RuntimeWarning: nanobind: type 'PolysetType' was already registered!
#15 0.370 
#15 0.370 Traceback (most recent call last):
#15 0.370   File "<string>", line 1, in <module>
#15 0.370   File "/src/basix/python/basix/__init__.py", line 7, in <module>
#15 0.370     from . import cell, finite_element, lattice, polynomials, quadrature, sobolev_spaces, variants
#15 0.370   File "/src/basix/python/basix/finite_element.py", line 3, in <module>
#15 0.370     from ._basixcpp import ElementFamily as _EF
#15 0.370 ImportError: cannot import name 'ElementFamily' from 'basix.finite_element._basixcpp' (/usr/local/lib/python3.10/dist-packages/basix/_basixcpp.cpython-310-x86_64-linux-gnu.so)
#15 0.375 free(): invalid pointer
#15 0.433 Aborted (core dumped)
#15 ERROR: process "/bin/sh -c python3 -c \"import basix\"" did not complete successfully: exit code: 134
------
 > [12/12] RUN python3 -c "import basix":
0.370 
0.370 Traceback (most recent call last):
0.370   File "<string>", line 1, in <module>
0.370   File "/src/basix/python/basix/__init__.py", line 7, in <module>
0.370     from . import cell, finite_element, lattice, polynomials, quadrature, sobolev_spaces, variants
0.370   File "/src/basix/python/basix/finite_element.py", line 3, in <module>
0.370     from ._basixcpp import ElementFamily as _EF
0.370 ImportError: cannot import name 'ElementFamily' from 'basix.finite_element._basixcpp' (/usr/local/lib/python3.10/dist-packages/basix/_basixcpp.cpython-310-x86_64-linux-gnu.so)
0.375 free(): invalid pointer
0.433 Aborted (core dumped)
------
Dockerfile:35
--------------------
  33 |     
  34 |     WORKDIR /tmp
  35 | >>> RUN python3 -c "import basix"
  36 |     
  37 |     # libgmp-dev
--------------------
ERROR: failed to solve: process "/bin/sh -c python3 -c \"import basix\"" did not complete successfully: exit code: 134

full log attached
log.txt

Can be reproduced with
python3 -m pip install -e ./basix -v as well.
Removing -e from either command makes the install work.

It's not broken - you need to use

pip install --no-build-isolation -e .

Proposed fix doesn't work. See updated dockerfile:

FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive
ARG TARGET_PLATFORM
RUN apt-get update && \
    apt-get install -y software-properties-common
RUN apt-get install -y git \
    cmake \
    gcc \
    g++ \
    ninja-build \
    libopenblas-dev \ 
    liblapack-dev
ENV DEB_PYTHON_INSTALL_LAYOUT=deb_system
RUN apt-get install -y python3-pip
RUN python3 -m pip install -U setuptools pip
RUN python3 -m pip install git+https://github.com/FEniCS/ufl.git

ENV CMAKE_BUILD_PARALLEL_LEVEL 2
WORKDIR /src
RUN git clone https://github.com/FEniCS/basix.git
RUN cd basix && \
    cmake -G Ninja -B build-dir -DCMAKE_BUILD_TYPE=Debug -S cpp/ && \
    cmake --build build-dir && \ 
    cmake --install build-dir


RUN python3 -m pip install scikit-build-core pyproject-metadata pathspec nanobind

RUN cd basix/python && \
    python3 -m pip install --no-build-isolation -e  . -v 


WORKDIR /tmp
RUN python3 -c "import basix"