Issue with anaconda installation of mshr ("CSGGeometry" referenced unknown base type "dolfin::Variable")

I have seen a lot of older versions of this issue for python 3.7-3.9 but none with any solution that has worked, and none for python 3.10 which is the new default for new conda environments. I have installed fenics and mshr in a new conda environment as follows:

conda create -n fenics -c conda-forge fenics mshr

I am able to import fenics, but this happens when I try to import mshr:

>>> import fenics
>>> import mshr
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jmetzger/anaconda3/envs/fenics/lib/python3.10/site-packages/mshr/__init__.py", line 24, in <module>
    from .cpp import Circle
ImportError: generic_type: type "CSGGeometry" referenced unknown base type "dolfin::Variable"

Here is the output of conda list

# packages in environment at /home/jmetzger/anaconda3/envs/fenics:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
binutils_impl_linux-64    2.36.1               h193b22a_2    conda-forge
binutils_linux-64         2.36                hf3e587d_10    conda-forge
boost-cpp                 1.74.0               h75c5d50_8    conda-forge
bzip2                     1.0.8                h7f98852_4    conda-forge
c-ares                    1.18.1               h7f98852_0    conda-forge
ca-certificates           2022.5.18.1          ha878542_0    conda-forge
cmake                     3.23.2               h5432695_0    conda-forge
eigen                     3.4.0                h4bd325d_0    conda-forge
expat                     2.4.8                h27087fc_0    conda-forge
fenics                    2019.1.0        py310hff52083_30    conda-forge
fenics-dijitso            2019.1.0        py310hff52083_30    conda-forge
fenics-dolfin             2019.1.0        py310h583d6c0_30    conda-forge
fenics-ffc                2019.1.0        py310hff52083_30    conda-forge
fenics-fiat               2019.1.0        py310hff52083_30    conda-forge
fenics-libdolfin          2019.1.0            hd78bcf9_30    conda-forge
fenics-ufl                2019.1.0        py310hff52083_30    conda-forge
fftw                      3.3.10          mpi_mpich_h8b92f0a_2    conda-forge
gcc_impl_linux-64         10.3.0              hf2f2afa_16    conda-forge
gcc_linux-64              10.3.0              hc39de41_10    conda-forge
gmp                       6.2.1                h58526e2_0    conda-forge
gmpy2                     2.1.2           py310h92f7908_0    conda-forge
gxx_impl_linux-64         10.3.0              hf2f2afa_16    conda-forge
gxx_linux-64              10.3.0              h2593f52_10    conda-forge
hdf5                      1.12.1          mpi_mpich_h5d83325_4    conda-forge
hypre                     2.24.0          mpi_mpich_hed3a557_1    conda-forge
icu                       70.1                 h27087fc_0    conda-forge
kernel-headers_linux-64   2.6.32              he073ed8_15    conda-forge
keyutils                  1.6.1                h166bdaf_0    conda-forge
krb5                      1.19.3               h08a2579_0    conda-forge
ld_impl_linux-64          2.36.1               hea4e1c9_2    conda-forge
libblas                   3.9.0           15_linux64_openblas    conda-forge
libcblas                  3.9.0           15_linux64_openblas    conda-forge
libcurl                   7.83.1               h2283fc2_0    conda-forge
libedit                   3.1.20191231         he28a2e2_2    conda-forge
libev                     4.33                 h516909a_1    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc-devel_linux-64     10.3.0              he6cfe16_16    conda-forge
libgcc-ng                 12.1.0              h8d9b700_16    conda-forge
libgfortran-ng            12.1.0              h69a702a_16    conda-forge
libgfortran5              12.1.0              hdcd56e2_16    conda-forge
libgomp                   12.1.0              h8d9b700_16    conda-forge
liblapack                 3.9.0           15_linux64_openblas    conda-forge
libnghttp2                1.47.0               he49606f_0    conda-forge
libnsl                    2.0.0                h7f98852_0    conda-forge
libopenblas               0.3.20          pthreads_h78a6416_0    conda-forge
libsanitizer              10.3.0              h26c7422_16    conda-forge
libssh2                   1.10.0               ha35d2d1_2    conda-forge
libstdcxx-devel_linux-64  10.3.0              he6cfe16_16    conda-forge
libstdcxx-ng              12.1.0              ha89aaad_16    conda-forge
libuuid                   2.32.1            h7f98852_1000    conda-forge
libuv                     1.43.0               h7f98852_0    conda-forge
libzlib                   1.2.12               h166bdaf_0    conda-forge
lz4-c                     1.9.3                h9c3ff4c_1    conda-forge
metis                     5.1.0             h58526e2_1006    conda-forge
mpc                       1.2.1                h9f54685_0    conda-forge
mpfr                      4.1.0                h9202a9a_1    conda-forge
mpi                       1.0                       mpich    conda-forge
mpi4py                    3.1.3           py310h37cc914_1    conda-forge
mpich                     4.0.2              h846660c_100    conda-forge
mpmath                    1.2.1              pyhd8ed1ab_0    conda-forge
mshr                      2019.1.0        py310hffed6ae_5    conda-forge
mumps-include             5.2.1               ha770c72_11    conda-forge
mumps-mpi                 5.2.1               h7ee95aa_11    conda-forge
ncurses                   6.3                  h27087fc_1    conda-forge
numpy                     1.22.4          py310h4ef5377_0    conda-forge
openssl                   3.0.3                h166bdaf_0    conda-forge
parmetis                  4.0.3             h2a9763c_1005    conda-forge
petsc                     3.17.2          real_h6ce3b2e_102    conda-forge
petsc4py                  3.17.2          real_h5faf7bb_100    conda-forge
pip                       22.1.2             pyhd8ed1ab_0    conda-forge
pkg-config                0.29.2            h36c2ea0_1008    conda-forge
pkgconfig                 1.5.5           py310hff52083_2    conda-forge
ptscotch                  6.0.9                hb499603_2    conda-forge
pybind11                  2.9.2           py310hbf28c38_1    conda-forge
pybind11-global           2.9.2           py310hbf28c38_1    conda-forge
python                    3.10.4          h2660328_0_cpython    conda-forge
python_abi                3.10                    2_cp310    conda-forge
readline                  8.1.2                h0f457ee_0    conda-forge
rhash                     1.4.1                h7f98852_0    conda-forge
scalapack                 2.2.0                hd931219_1    conda-forge
scotch                    6.0.9                hb2e6521_2    conda-forge
setuptools                62.3.4          py310hff52083_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
slepc                     3.17.1          real_ha2e80f3_101    conda-forge
slepc4py                  3.17.1          real_h7df52cc_102    conda-forge
sqlite                    3.38.5               h4ff8645_0    conda-forge
suitesparse               5.10.1               h9e50725_1    conda-forge
superlu                   5.2.2                h00795ac_0    conda-forge
superlu_dist              7.2.0                h25dcc4a_0    conda-forge
sympy                     1.10.1          py310hff52083_0    conda-forge
sysroot_linux-64          2.12                he073ed8_15    conda-forge
tbb                       2021.5.0             h924138e_1    conda-forge
tk                        8.6.12               h27826a3_0    conda-forge
tzdata                    2022a                h191b570_0    conda-forge
wheel                     0.37.1             pyhd8ed1ab_0    conda-forge
xz                        5.2.5                h516909a_1    conda-forge
yaml                      0.2.5                h7f98852_2    conda-forge
zlib                      1.2.12               h166bdaf_0    conda-forge
zstd                      1.5.2                h8a70e8d_1    conda-forge

Again, I have tried the other solutions with various combinations of fenics and mshr builds and nothing has worked. I usually get the same issue, but with some builds of fenics I am unable to import fenics as well (missing certain libraries or files).

Mshr has been deprecated for a long time, and I would strongly suggest moving to more modern software such as GMSH.

2 Likes