Anaconda Installation of Fenics and Mshr

Hi all,

In June of 2019, I installed Fenics and Mshr via Anaconda on Ubuntu using the command:

conda create -n fenicsproject -c conda-forge python=3.7 fenics mshr ipython.

Since then, I have used the same command multiple times and everything works fine. However, a week ago I tried the same thing and trying to import mshr using from mshr import * I get the following error:

File "/home/hwan/Documents/Github_Codes/Thermal_Fin_Heat_Simulator/Generate_and_Save_Thermal_Fin_Data.py", line 18, in <module>
    from Thermal_Fin_Heat_Simulator.Utilities.forward_solve import Fin

  File "../Thermal_Fin_Heat_Simulator/Utilities/forward_solve.py", line 3, in <module>
    from mshr import *

  File "/home/hwan/anaconda3/envs/fenics_env_2019/lib/python3.7/site-packages/mshr/__init__.py", line 24, in <module>
    from .cpp import Circle

ImportError: generic_type: type "CSGGeometry" referenced unknown base type "dolfin::Variable"

Has there been a change to the 2019.1.0 version? Anyone else encounter this issue? I reverted to the 2018 version and everything is fine. Also, what version does the command conda install -c conda-forge fenics, is it 2019.1.0 for python 3.8?

Any assistance will be greatly appreciated!

Best regards,
Hwan

1 Like

Hi Hwan,

I’m having the same problem as you. Could you please tell me how you fix it?

Best,
Li

Hi Li,

Unfortunately I did not fix it. What I did instead is install the 2018 version and am now currently working with that. I use the following commands:

conda install -c conda-forge fenics=2018
conda install -c conda-forge mshr=2018.

Best regards,
Hwan

1 Like

Same problem! Does anyone know what causes 2019 to stop working?

Dear people,

I had a similar problem and after a lot of trial-and-error, the following fix worked for me. From the file __init__.py in the subfolder lib/python3.7/site-packages/mshr of the environment in which the problem occurred, I removed the following lines:

from .cpp import Circle
from .cpp import Ellipse
from .cpp import Rectangle
from .cpp import Polygon
from .cpp import Sphere
from .cpp import Box
from .cpp import Cylinder
from .cpp import Cone
from .cpp import Tetrahedron
from .cpp import Surface3D
from .cpp import Ellipsoid
from .cpp import Rectangle
from .cpp import Extrude2D
from .cpp import CSGCGALDomain3D
from .cpp import CSGIntersection
from .cpp import CSGDifference
from .cpp import CSGUnion
from .cpp import CSGScaling
from .cpp import CSGTranslation
from .cpp import CSGRotation
from .cpp import CSGGeometries
from .cpp import UnitSphereMesh
from .cpp import CSGCGALMeshGenerator3D
from .cpp import TetgenMeshGenerator3D
from .cpp import CSGCGALDomain2D
from .cpp import CSGCGALMeshGenerator2D
from .cpp import generate_mesh

thereby leaving only one active statement in the whole file, namely:

import dolfin

Hopefully this works for you too.

Kind regards, Jakob

Your radical cure fixed indeed the problem with from mshr import *
but if you need e.g. Rectangle in your code you get an error message

----> 2 domaine = Rectangle( Point(0,0) , Point(25,2))

NameError: name ‘Rectangle’ is not defined

I did the same as Hwan but to avoid confusing versions I created a new environment which I called fenics2018 with the 2018 version of fenics and mshr
since I work with jupyter notebook I did the following

conda create -n fenics2018 -c conda-forge python=3.7 ipython jupyter fenics=2018 mshr=2018

later I added matplotlib also
conda install -n fenics2018 matplotlib

then everything works.

I wonder why with mshr 2019.1.0 and fenics 2019.1.0
I get the following error

ImportError Traceback (most recent call last)
in
----> 1 from mshr import *

/anaconda3/envs/fenicsproject/lib/python3.7/site-packages/mshr/init.py in
22 import dolfin
23
—> 24 from .cpp import Circle
25 from .cpp import Ellipse
26 from .cpp import Rectangle

ImportError: dlopen(/anaconda3/envs/fenicsproject/lib/python3.7/site-packages/mshr/cpp.cpython-37m-darwin.so, 2): Library not loaded: @rpath/libslepc.3.12.dylib
Referenced from: /anaconda3/envs/fenicsproject/lib/libmshr.2019.1.dylib
Reason: image not found

1 Like

There’s a reference to slepc there, have you got SLEPc installed?

1 Like

Thank you for your suggestion but slepc is installed I just checked with conda list
slepc 3.11.2 h1ce4c84_1 conda-forge
slepc4py 3.11.0 py37hc459697_0 conda-forge

By noticing that the error message could not load libslepc.3.12 I I installed slepc 3.12and everything works now.

So the cure is simply to conda install -n fenicsproject -c conda-forge slepc=3.12
replacing fenicsproject by your fenics environement name

1 Like

Hello,

I have the same error, even with slepc 3.12:

ImportError: generic_type: type “CSGGeometry” referenced unknown base type “dolfin::Variable”

conda list
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       1_gnu    conda-forge
backcall                  0.2.0                      py_0  
binutils_impl_linux-64    2.34                 h53a641e_7    conda-forge
binutils_linux-64         2.34                hc952b39_20    conda-forge
boost-cpp                 1.72.0               h7b93d67_2    conda-forge
bzip2                     1.0.8                h516909a_2    conda-forge
c-ares                    1.16.1               h516909a_0    conda-forge
ca-certificates           2020.6.20            hecda079_0    conda-forge
certifi                   2020.6.20        py38h32f6830_0    conda-forge
cloudpickle               1.5.0                      py_0  
cmake                     3.18.0               h5c55442_0    conda-forge
cycler                    0.10.0                     py_2    conda-forge
decorator                 4.4.2                      py_0  
eigen                     3.3.7             hc9558a2_1001    conda-forge
expat                     2.2.9                he1b5a44_2    conda-forge
fastcache                 1.1.0            py38h1e0a361_1    conda-forge
fenics                    2019.1.0        py38h32f6830_10    conda-forge
fenics-dijitso            2019.1.0                  py_10    conda-forge
fenics-dolfin             2019.1.0        py38hd3deb98_10    conda-forge
fenics-ffc                2019.1.0                  py_10    conda-forge
fenics-fiat               2019.1.0                  py_10    conda-forge
fenics-libdolfin          2019.1.0            h8f7d7a8_10    conda-forge
fenics-ufl                2019.1.0                  py_10    conda-forge
freetype                  2.10.2               he06d7ca_0    conda-forge
gcc_impl_linux-64         7.5.0                hd420e75_6    conda-forge
gcc_linux-64              7.5.0               h09487f9_20    conda-forge
gmp                       6.2.0                he1b5a44_2    conda-forge
gmpy2                     2.1.0b1          py38h04dde30_0    conda-forge
gxx_impl_linux-64         7.5.0                hdf63c60_6    conda-forge
gxx_linux-64              7.5.0               h09487f9_20    conda-forge
hdf5                      1.10.6          mpi_mpich_ha7d0aea_1    conda-forge
hypre                     2.18.2               hc98498a_1    conda-forge
icu                       67.1                 he1b5a44_0    conda-forge
ipykernel                 5.3.4            py38h5ca1d4c_0  
ipython                   7.16.1           py38h5ca1d4c_0  
ipython_genutils          0.2.0                    py38_0  
jedi                      0.17.0                   py38_0  
jpeg                      9d                   h516909a_0    conda-forge
jupyter_client            6.1.6                      py_0  
jupyter_core              4.6.3                    py38_0  
kiwisolver                1.2.0            py38hbf85e49_0    conda-forge
krb5                      1.17.1               hfafb76e_2    conda-forge
lcms2                     2.11                 hbd6801e_0    conda-forge
ld_impl_linux-64          2.34                 h53a641e_7    conda-forge
libblas                   3.8.0               17_openblas    conda-forge
libcblas                  3.8.0               17_openblas    conda-forge
libcurl                   7.71.1               hcdd3856_4    conda-forge
libedit                   3.1.20191231         h46ee950_1    conda-forge
libev                     4.33                 h516909a_0    conda-forge
libffi                    3.2.1             he1b5a44_1007    conda-forge
libgcc-ng                 9.3.0               h24d8f2e_14    conda-forge
libgfortran-ng            7.5.0               hdf63c60_14    conda-forge
libgomp                   9.3.0               h24d8f2e_14    conda-forge
liblapack                 3.8.0               17_openblas    conda-forge
libnghttp2                1.41.0               hab1572f_1    conda-forge
libopenblas               0.3.10          pthreads_hb3c22a3_4    conda-forge
libpng                    1.6.37               hed695b0_2    conda-forge
libsodium                 1.0.18               h7b6447c_0  
libssh2                   1.9.0                hab1572f_5    conda-forge
libstdcxx-ng              9.3.0               hdf63c60_14    conda-forge
libtiff                   4.1.0                hc7e4089_6    conda-forge
libuv                     1.38.0               h516909a_0    conda-forge
libwebp-base              1.1.0                h516909a_3    conda-forge
lz4-c                     1.9.2                he1b5a44_1    conda-forge
matplotlib                3.3.0                         1    conda-forge
matplotlib-base           3.3.0            py38h91b0d89_1    conda-forge
metis                     5.1.0             he1b5a44_1005    conda-forge
mpc                       1.1.0             h04dde30_1009    conda-forge
mpfr                      4.0.2                he80fd80_1    conda-forge
mpi                       1.0                       mpich    conda-forge
mpi4py                    3.0.3            py38h4a80816_1    conda-forge
mpich                     3.3.2                hc856adb_0    conda-forge
mpmath                    1.1.0                      py_0    conda-forge
mshr                      2019.1.0         py38hf9f41d3_3    conda-forge
mumps-include             5.2.1                         6    conda-forge
mumps-mpi                 5.2.1                h645f208_6    conda-forge
ncurses                   6.2                  he1b5a44_1    conda-forge
numpy                     1.19.1           py38h8854b6b_0    conda-forge
olefile                   0.46                       py_0    conda-forge
openssl                   1.1.1g               h516909a_1    conda-forge
parmetis                  4.0.3             h9f7b9cf_1005    conda-forge
parso                     0.8.0                      py_0  
petsc                     3.12.4               h432f2ec_0    conda-forge
petsc4py                  3.12.0           py38h30bdb2a_4    conda-forge
pexpect                   4.8.0                    py38_0  
pickleshare               0.7.5                 py38_1000  
pillow                    7.2.0            py38h9776b28_1    conda-forge
pip                       20.2.2                     py_0    conda-forge
pkg-config                0.29.2            h516909a_1006    conda-forge
pkgconfig                 1.4.0            py38h32f6830_0    conda-forge
prompt-toolkit            3.0.5                      py_0  
ptscotch                  6.0.8                he9f2703_1    conda-forge
ptyprocess                0.6.0                    py38_0  
pybind11                  2.5.0            py38hbf85e49_0    conda-forge
pygments                  2.6.1                      py_0  
pyparsing                 2.4.7              pyh9f0ad1d_0    conda-forge
python                    3.8.5           h4d41432_2_cpython    conda-forge
python-dateutil           2.8.1                      py_0  
python_abi                3.8                      1_cp38    conda-forge
pyzmq                     19.0.1           py38he6710b0_1  
readline                  8.0                  he28a2e2_2    conda-forge
rhash                     1.3.6             h14c3975_1001    conda-forge
scalapack                 2.0.2             hfacbc1e_1008    conda-forge
scotch                    6.0.8                h0eec0ba_1    conda-forge
setuptools                49.6.0           py38h32f6830_0    conda-forge
six                       1.15.0             pyh9f0ad1d_0    conda-forge
slepc                     3.12.2               h76dbdef_0    conda-forge
slepc4py                  3.12.0           py38hb2ee469_1    conda-forge
spyder-kernels            1.9.2                    py38_0  
sqlite                    3.32.3               h4cf870e_1    conda-forge
suitesparse               5.6.0                h717dc36_0    conda-forge
superlu                   5.2.1             hfe2efc7_1207    conda-forge
superlu_dist              6.2.0                h5e15a89_2    conda-forge
sympy                     1.6.2            py38h32f6830_0    conda-forge
tbb                       2020.1               hc9558a2_0    conda-forge
tk                        8.6.10               hed695b0_0    conda-forge
tornado                   6.0.4            py38h7b6447c_1  
traitlets                 4.3.3                    py38_0  
wcwidth                   0.2.5                      py_0  
wheel                     0.34.2                     py_1    conda-forge
wurlitzer                 2.0.1                    py38_0  
xz                        5.2.5                h516909a_1    conda-forge
zeromq                    4.3.2                he6710b0_2  
zlib                      1.2.11            h516909a_1007    conda-forge

Sorry for answering so late. Back from vacations.

May be install the latest version of slepc 3.13 instead of 3.12?

From your conda list, some of your packages are more recent than mine.

I provide below the output of conda list on my machine (MacOS 10.14.5), just in case.

conda list

#packages in environment at /anaconda3/envs/fenicsproject:

#Name Version Build Channel
appnope 0.1.0 py37_0
attrs 19.2.0 py_0
autopep8 1.5.2 pypi_0 pypi
backcall 0.1.0 py37_0
blas 2.14 openblas conda-forge
bleach 3.1.0 py37_0
boost-cpp 1.72.0 hdf9ef73_0 conda-forge
bzip2 1.0.8 h01d97ff_1 conda-forge
ca-certificates 2020.4.5.1 hecc5488_0 conda-forge
certifi 2020.4.5.1 py37hc8dfbb8_0 conda-forge
cmake 3.15.4 h6c18c4b_0 conda-forge
curl 7.65.3 h22ea746_0 conda-forge
cycler 0.10.0 py37_0
decorator 4.4.0 py37_1
defusedxml 0.6.0 py_0
eigen 3.3.7 h04f5b5a_1000 conda-forge
entrypoints 0.3 py37_0
expat 2.2.5 h6de7cb9_1003 conda-forge
fastcache 1.1.0 py37h01d97ff_0 conda-forge
fenics 2019.1.0 py37_9 conda-forge
fenics-dijitso 2019.1.0 py_7 conda-forge
fenics-dolfin 2019.1.0 py37hb0736e2_9 conda-forge
fenics-ffc 2019.1.0 py_7 conda-forge
fenics-fiat 2019.1.0 py_7 conda-forge
fenics-libdolfin 2019.1.0 hb974ea8_9 conda-forge
fenics-ufl 2019.1.0 py_7 conda-forge
freetype 2.9.1 hb4e5f40_0
gmp 6.2.0 h4a8c4bd_2 conda-forge
gmpy2 2.1.0b1 py37h1744cca_0 conda-forge
hdf5 1.10.5 mpi_mpich_h3734b49_1004 conda-forge
hypre 2.18.2 hc9ba2bc_1 conda-forge
icu 64.2 h6de7cb9_1 conda-forge
ipykernel 5.1.2 py37h39e3cac_0
ipython 7.8.0 py37h39e3cac_0
ipython_genutils 0.2.0 py37_0
jedi 0.15.1 py37_0
jinja2 2.10.3 py_0
jsonschema 3.0.2 py37_0
jupyter_client 5.3.4 py37_0
jupyter_contrib_core 0.3.3 py_2 conda-forge
jupyter_contrib_nbextensions 0.5.1 py37_0 conda-forge
jupyter_core 4.6.0 py37_0
jupyter_highlight_selected_word 0.2.0 py37_1000 conda-forge
jupyter_latex_envs 1.4.4 py37_1000 conda-forge
jupyter_nbextensions_configurator 0.4.1 py37_0 conda-forge
kiwisolver 1.1.0 py37h0a44026_0
krb5 1.16.3 hcfa6398_1001 conda-forge
libblas 3.8.0 14_openblas conda-forge
libcblas 3.8.0 14_openblas conda-forge
libcurl 7.65.3 h16faf7d_0 conda-forge
libcxx 10.0.0 h1af66ff_2 conda-forge
libcxxabi 4.0.1 hcfea43d_1 conda-forge
libedit 3.1.20170329 hcfe32e1_1001 conda-forge
libffi 3.2.1 h6de7cb9_1006 conda-forge
libgfortran 4.0.0 2 conda-forge
libiconv 1.15 h01d97ff_1005 conda-forge
liblapack 3.8.0 14_openblas conda-forge
liblapacke 3.8.0 14_openblas conda-forge
libopenblas 0.3.7 h4bb4525_2 conda-forge
libpng 1.6.37 ha441bb4_0
libsodium 1.0.16 h3efe00b_0
libssh2 1.8.2 hcdc9a53_2 conda-forge
libuv 1.32.0 h01d97ff_0 conda-forge
libxml2 2.9.10 h53d96d6_0 conda-forge
libxslt 1.1.33 h320ff13_0 conda-forge
llvm-openmp 9.0.0 h40edb58_0 conda-forge
lxml 4.5.1 py37heb1707f_0 conda-forge
markupsafe 1.1.1 py37h1de35cc_0
matplotlib 3.1.1 py37h54f8f79_0
metis 5.1.0 h6de7cb9_1004 conda-forge
mistune 0.8.4 py37h1de35cc_0
mpc 1.1.0 h3aece09_1006 conda-forge
mpfr 4.0.2 h44b798e_0 conda-forge
mpi 1.0 mpich conda-forge
mpi4py 3.0.3 py37h88507a1_1 conda-forge
mpich 3.3.2 hc856adb_0 conda-forge
mpmath 1.1.0 py_0 conda-forge
mshr 2019.1.0 py37h8c59516_3 conda-forge
mumps-include 5.2.1 6 conda-forge
mumps-mpi 5.2.1 hcf7f05f_6 conda-forge
nbconvert 5.6.0 py37_1
nbformat 4.4.0 py37_0
ncurses 6.1 h0a44026_1002 conda-forge
notebook 6.0.1 py37_0
numpy 1.16.4 py37h6b0580a_0 conda-forge
openssl 1.1.1g h0b31af3_0 conda-forge
pandoc 2.2.3.2 0
pandocfilters 1.4.2 py37_1
parmetis 4.0.3 hbc1d92b_1005 conda-forge
parso 0.5.1 py_0
petsc 3.12.4 h6ceeb6d_0 conda-forge
petsc4py 3.12.0 py37h833b260_4 conda-forge
pexpect 4.7.0 py37_0
pickleshare 0.7.5 py37_0
pip 19.3 py37_0 conda-forge
pkg-config 0.29.2 h112b980_1005 conda-forge
pkgconfig 1.3.1 py37_1001 conda-forge
prometheus_client 0.7.1 py_0
prompt_toolkit 2.0.10 py_0
ptscotch 6.0.8 h8c5ff5d_1 conda-forge
ptyprocess 0.6.0 py37_0
pybind11 2.4.3 py37ha1cc60f_3 conda-forge
pycodestyle 2.6.0 pypi_0 pypi
pygments 2.4.2 py_0
pyparsing 2.4.2 py_0
pyrsistent 0.15.4 py37h1de35cc_0
python 3.7.3 h93065d6_1 conda-forge
python-dateutil 2.8.0 py37_0
python_abi 3.7 1_cp37m conda-forge
pytz 2019.3 py_0
pyyaml 5.3.1 py37h9bfed18_0 conda-forge
pyzmq 18.1.0 py37h0a44026_0
readline 8.0 hcfe32e1_0 conda-forge
rhash 1.3.6 h1de35cc_1001 conda-forge
scalapack 2.0.2 h4fb7227_1008 conda-forge
scotch 6.0.8 h01cae8c_0 conda-forge
send2trash 1.5.0 py37_0
setuptools 41.4.0 py37_0 conda-forge
six 1.12.0 py37_1000 conda-forge
slepc 3.12.2 hefb7033_0 conda-forge
slepc4py 3.12.0 py37h00bfe04_1 conda-forge
sqlite 3.30.1 h93121df_0 conda-forge
suitesparse 5.6.0 h0e59142_0 conda-forge
superlu 5.2.1 hc209f47_1207 conda-forge
superlu_dist 6.2.0 h32cdba5_1 conda-forge
sympy 1.4 py37_0 conda-forge
tbb 2019.9 ha1b3eb9_0 conda-forge
terminado 0.8.2 py37_0
testpath 0.4.2 py37_0
tk 8.6.9 h2573ce8_1003 conda-forge
tornado 6.0.3 py37h1de35cc_0
traitlets 4.3.3 py37_0
wcwidth 0.1.7 py37_0
webencodings 0.5.1 py37_1
wheel 0.33.6 py37_0 conda-forge
xz 5.2.4 h1de35cc_1001 conda-forge
yaml 0.2.4 h0b31af3_0 conda-forge
zeromq 4.3.1 h0a44026_3
zlib 1.2.11 h0b31af3_1006 conda-forge

As far as I can tell, this error happens when the mshr library is out-of-sync with the dolfin library. This might happen, for instance, if the dolfin package is updated or rebuilt, but the mshr package was not rebuilt against the new dolfin.

Looks like @azerad’s package versions are now self-consistent with each other.

Dear,

I redid the installations of both fenics and mshr this week and the problem still persists!

I can’t update slepc to version 3.13

i use mac os.

Hello,

I wanted to stay with the 2019 version of fenics, so I tried several builds of mshr 2019.1.0 available on conda-forge. The second newest build worked for me. I created a new Conda environment with

conda create -n fenicstest -c conda-forge mshr=2019.1.0=py38h2af9582_2

(the correct version of fenics is installed automatically because of dependencies) and in this environment the ImportError disappeared.

The build id py38h2af9582_2 above is for the macOS version, you can get the build ids of all available builds for your system via:

conda search mshr -c conda-forge

Maybe this works for you too…

Best regards
Martin

7 Likes

Dear Martin,

Thank you so much, it worked!

I had already resolved installing the Docker Toolbox on the mac. But I prefer to use anaconda.

Hi,

Thank you! This also worked for me. I’m using

conda install -c conda-forge fenics mshr=2019.1.0=py38h255090a_2

on Ubuntu 18.04.