Difficulty getting fenics working

Hi

I’m trying to install fenicsx for the first time and get it working. I’ve installed it on a conda environment in an ubuntu subsystem on a windows machine. I’m working in VSCode and VScode is running the virtual ubuntu machine without difficulty.

However, when I try to inport the the dolfinx module (or indeed run any of the sample code from the fenics website) I get the following error message.

AttributeError: module ‘ufl.sobolevspace’ has no attribute ‘HInf’

Any help resolving this would be greatly appreciated

This usually means that you have installed conflicting packages. This usually happens when you try to install both legacy dolfin and dolfinx in the same environment.

Please provide the output of conda env export and the full traceback of your error message.

It would also be helpful to see what lines you used to install DOLFINx with when using conda as well.

Thanks for getting back so quickly. In response to your questions

The output of conda env export is

name: fenicsx-env
channels:

  • conda-forge
  • defaults
    dependencies:
  • _libgcc_mutex=0.1=conda_forge
  • _openmp_mutex=4.5=2_gnu
  • aiohttp=3.9.3=py312h98912ed_1
  • aiosignal=1.3.1=pyhd8ed1ab_0
  • alsa-lib=1.2.11=hd590300_1
  • aom=3.8.2=h59595ed_0
  • attr=2.5.1=h166bdaf_1
  • attrs=23.2.0=pyh71513ae_0
  • binutils_impl_linux-64=2.40=hf600244_0
  • binutils_linux-64=2.40=hdade7a5_3
  • blosc=1.21.5=h0f2a231_0
  • brotli=1.1.0=hd590300_1
  • brotli-bin=1.1.0=hd590300_1
  • brotli-python=1.1.0=py312h30efb56_1
  • bzip2=1.0.8=hd590300_5
  • c-ares=1.28.1=hd590300_0
  • c-blosc2=2.13.2=hb4ffafa_0
  • ca-certificates=2024.2.2=hbcca054_0
  • cairo=1.18.0=h3faef2a_0
  • certifi=2024.2.2=pyhd8ed1ab_0
  • cffi=1.16.0=py312hf06ca03_0
  • charset-normalizer=3.3.2=pyhd8ed1ab_0
  • contourpy=1.2.0=py312h8572e83_0
  • cycler=0.12.1=pyhd8ed1ab_0
  • dav1d=1.2.1=hd590300_0
  • dbus=1.13.6=h5008d03_3
  • double-conversion=3.3.0=h59595ed_0
  • eigen=3.4.0=h00ab1b0_0
  • expat=2.5.0=hcb278e6_1
  • fenics-basix=0.7.0=py312h5b9907d_1
  • fenics-basix-pybind11-abi=0.4.12=h5b9907d_1
  • fenics-dolfinx=0.7.3=py312h55dd49f_102
  • fenics-ffcx=0.7.0=pyh4af843d_0
  • fenics-libbasix=0.7.0=hfdc072b_1
  • fenics-libdolfinx=0.7.3=h1f5ddee_102
  • fenics-ufcx=0.7.0=h4af843d_0
  • fenics-ufl=2023.2.0=pyhd8ed1ab_0
  • ffmpeg=6.1.1=gpl_h38e077a_106
  • fftw=3.3.10=mpi_mpich_h5537406_8
  • font-ttf-dejavu-sans-mono=2.37=hab24e00_0
  • font-ttf-inconsolata=3.000=h77eed37_0
  • font-ttf-source-code-pro=2.038=h77eed37_0
  • font-ttf-ubuntu=0.83=h77eed37_1
  • fontconfig=2.14.2=h14ed4e7_0
  • fonts-conda-ecosystem=1=0
  • fonts-conda-forge=1=0
  • fonttools=4.50.0=py312h98912ed_0
  • freetype=2.12.1=h267a509_2
  • fribidi=1.0.10=h36c2ea0_0
  • frozenlist=1.4.1=py312h98912ed_0
  • gcc_impl_linux-64=12.3.0=he2b93b0_5
  • gcc_linux-64=12.3.0=h6477408_3
  • gettext=0.21.1=h27087fc_0
  • gl2ps=1.4.2=h0708190_0
  • glew=2.1.0=h9c3ff4c_2
  • glib=2.80.0=hf2295e7_1
  • glib-tools=2.80.0=hde27a5a_1
  • gmp=6.3.0=h59595ed_1
  • gnutls=3.7.9=hb077bed_0
  • graphite2=1.3.13=h59595ed_1003
  • gst-plugins-base=1.22.9=h8e1006c_0
  • gstreamer=1.22.9=h98fc4e7_0
  • gxx_impl_linux-64=12.3.0=he2b93b0_5
  • gxx_linux-64=12.3.0=h4a1b8e8_3
  • harfbuzz=8.3.0=h3d44ed6_0
  • hdf4=4.2.15=h2a13503_7
  • hdf5=1.14.3=mpi_mpich_ha2c2bf8_0
  • hypre=2.28.0=mpi_mpich_h716cb5e_0
  • icu=73.2=h59595ed_0
  • idna=3.6=pyhd8ed1ab_0
  • jsoncpp=1.9.5=h4bd325d_1
  • kahip=3.16=h78159e9_2
  • kahip-python=3.16=py312h79e6366_2
  • kernel-headers_linux-64=2.6.32=he073ed8_17
  • keyutils=1.6.1=h166bdaf_0
  • kiwisolver=1.4.5=py312h8572e83_1
  • krb5=1.21.2=h659d440_0
  • lame=3.100=h166bdaf_1003
  • lcms2=2.16=hb7c19ff_0
  • ld_impl_linux-64=2.40=h41732ed_0
  • lerc=4.0.0=h27087fc_0
  • libabseil=20240116.1=cxx17_h59595ed_2
  • libadios2=2.9.2=mpi_mpich_h69321e2_1
  • libaec=1.1.3=h59595ed_0
  • libass=0.17.1=h8fe9dca_1
  • libblas=3.9.0=21_linux64_openblas
  • libboost=1.84.0=h8013b2b_2
  • libboost-devel=1.84.0=h00ab1b0_2
  • libboost-headers=1.84.0=ha770c72_2
  • libbrotlicommon=1.1.0=hd590300_1
  • libbrotlidec=1.1.0=hd590300_1
  • libbrotlienc=1.1.0=hd590300_1
  • libcap=2.69=h0f662aa_0
  • libcblas=3.9.0=21_linux64_openblas
  • libclang=15.0.7=default_h127d8a8_5
  • libclang13=15.0.7=default_h5d6823c_5
  • libcups=2.3.3=h4637d8d_4
  • libcurl=8.7.1=hca28451_0
  • libdeflate=1.20=hd590300_0
  • libdrm=2.4.120=hd590300_0
  • libedit=3.1.20191231=he28a2e2_2
  • libev=4.33=hd590300_2
  • libevent=2.1.12=hf998b51_1
  • libexpat=2.5.0=hcb278e6_1
  • libffi=3.4.2=h7f98852_5
  • libflac=1.4.3=h59595ed_0
  • libgcc-devel_linux-64=12.3.0=h8bca6fd_105
  • libgcc-ng=13.2.0=h807b86a_5
  • libgcrypt=1.10.3=hd590300_0
  • libgfortran-ng=13.2.0=h69a702a_5
  • libgfortran5=13.2.0=ha4646dd_5
  • libglib=2.80.0=hf2295e7_1
  • libglu=9.0.0=hac7e632_1003
  • libgomp=13.2.0=h807b86a_5
  • libgpg-error=1.48=h71f35ed_0
  • libhwloc=2.9.3=default_h554bfaf_1009
  • libiconv=1.17=hd590300_2
  • libidn2=2.3.7=hd590300_0
  • libjpeg-turbo=3.0.0=hd590300_1
  • liblapack=3.9.0=21_linux64_openblas
  • libllvm15=15.0.7=hb3ce162_4
  • libnetcdf=4.9.2=nompi_h9612171_113
  • libnghttp2=1.58.0=h47da74e_1
  • libnsl=2.0.1=hd590300_0
  • libogg=1.3.4=h7f98852_1
  • libopenblas=0.3.26=pthreads_h413a1c8_0
  • libopenvino=2024.0.0=h2e90f83_4
  • libopenvino-auto-batch-plugin=2024.0.0=hd5fc58b_4
  • libopenvino-auto-plugin=2024.0.0=hd5fc58b_4
  • libopenvino-hetero-plugin=2024.0.0=h3ecfda7_4
  • libopenvino-intel-cpu-plugin=2024.0.0=h2e90f83_4
  • libopenvino-intel-gpu-plugin=2024.0.0=h2e90f83_4
  • libopenvino-ir-frontend=2024.0.0=h3ecfda7_4
  • libopenvino-onnx-frontend=2024.0.0=h757c851_4
  • libopenvino-paddle-frontend=2024.0.0=h757c851_4
  • libopenvino-pytorch-frontend=2024.0.0=h59595ed_4
  • libopenvino-tensorflow-frontend=2024.0.0=hca94c1a_4
  • libopenvino-tensorflow-lite-frontend=2024.0.0=h59595ed_4
  • libopus=1.3.1=h7f98852_1
  • libpciaccess=0.18=hd590300_0
  • libpng=1.6.43=h2797004_0
  • libpq=16.2=h33b98f1_1
  • libprotobuf=4.25.3=h08a7969_0
  • libptscotch=7.0.4=h2376d02_1
  • libsanitizer=12.3.0=h0f45ef3_5
  • libscotch=7.0.4=h91e35bf_1
  • libsndfile=1.2.2=hc60ed4a_1
  • libsodium=1.0.18=h36c2ea0_1
  • libsqlite=3.45.2=h2797004_0
  • libssh2=1.11.0=h0841786_0
  • libstdcxx-devel_linux-64=12.3.0=h8bca6fd_105
  • libstdcxx-ng=13.2.0=h7e041cc_5
  • libsystemd0=255=h3516f8a_1
  • libtasn1=4.19.0=h166bdaf_0
  • libtheora=1.1.1=h7f98852_1005
  • libtiff=4.6.0=h1dd3fc0_3
  • libunistring=0.9.10=h7f98852_0
  • libuuid=2.38.1=h0b41bf4_0
  • libva=2.21.0=hd590300_0
  • libvorbis=1.3.7=h9c3ff4c_0
  • libvpx=1.14.0=h59595ed_0
  • libwebp-base=1.3.2=hd590300_0
  • libxcb=1.15=h0b41bf4_0
  • libxcrypt=4.4.36=hd590300_1
  • libxkbcommon=1.7.0=h662e7e4_0
  • libxml2=2.12.6=h232c23b_1
  • libzip=1.10.1=h2629f0a_3
  • libzlib=1.2.13=hd590300_5
  • loguru=0.7.2=py312h7900ff3_1
  • lz4-c=1.9.4=hcb278e6_0
  • matplotlib-base=3.8.3=py312he5832f3_0
  • metis=5.1.0=h59595ed_1007
  • mpfr=4.2.1=h9458935_0
  • mpg123=1.32.4=h59595ed_0
  • mpi=1.0=mpich
  • mpi4py=3.1.5=py312h5256a87_1
  • mpich=4.2.0=h846660c_100
  • multidict=6.0.5=py312h98912ed_0
  • mumps-include=5.6.2=ha770c72_4
  • mumps-mpi=5.6.2=h416f8d4_4
  • munkres=1.1.4=pyh9f0ad1d_0
  • mysql-common=8.0.33=hf1915f5_6
  • mysql-libs=8.0.33=hca2cd23_6
  • ncurses=6.4.20240210=h59595ed_0
  • nettle=3.9.1=h7ab15ed_0
  • nlohmann_json=3.11.3=h59595ed_0
  • nspr=4.35=h27087fc_0
  • nss=3.98=h1d7d5a4_0
  • numpy=1.26.4=py312heda63a1_0
  • ocl-icd=2.3.2=hd590300_1
  • openh264=2.4.1=h59595ed_0
  • openjpeg=2.5.2=h488ebb8_0
  • openssl=3.2.1=hd590300_1
  • p11-kit=0.24.1=hc5aa10d_0
  • packaging=24.0=pyhd8ed1ab_0
  • parmetis=4.0.3=h2a9763c_1005
  • pcre2=10.43=hcad00b1_0
  • petsc=3.20.6=real_h247c841_100
  • petsc4py=3.20.5=real_h098918d_100
  • pillow=10.2.0=py312hf3581a9_0
  • pip=24.0=pyhd8ed1ab_0
  • pixman=0.43.2=h59595ed_0
  • pkg-config=0.29.2=h36c2ea0_1008
  • platformdirs=4.2.0=pyhd8ed1ab_0
  • pooch=1.8.1=pyhd8ed1ab_0
  • proj=9.3.1=h1d62c97_0
  • pthread-stubs=0.4=h36c2ea0_1001
  • ptscotch=7.0.4=h23d43cc_1
  • pugixml=1.14=h59595ed_0
  • pulseaudio-client=16.1=hb77b528_5
  • pybind11-abi=4=hd8ed1ab_3
  • pycparser=2.22=pyhd8ed1ab_0
  • pyparsing=3.1.2=pyhd8ed1ab_0
  • pysocks=1.7.1=pyha2e5f31_6
  • python=3.12.2=hab00c5b_0_cpython
  • python-dateutil=2.9.0=pyhd8ed1ab_0
  • python_abi=3.12=4_cp312
  • pyvista=0.43.4=pyhd8ed1ab_0
  • qt-main=5.15.8=h5810be5_19
  • readline=8.2=h8228510_1
  • requests=2.31.0=pyhd8ed1ab_0
  • scalapack=2.2.0=hd931219_1
  • scooby=0.9.2=pyhd8ed1ab_0
  • scotch=7.0.4=h23d43cc_1
  • setuptools=69.2.0=pyhd8ed1ab_0
  • six=1.16.0=pyh6c4a22f_0
  • slepc=3.20.2=real_h31e5b42_100
  • slepc4py=3.20.2=real_h421bb0b_100
  • snappy=1.1.10=h9fff704_0
  • sqlite=3.45.2=h2c6b66d_0
  • suitesparse=5.10.1=h5a4f163_3
  • superlu=5.2.2=h00795ac_0
  • superlu_dist=8.2.1=he925d4f_1
  • svt-av1=1.8.0=h59595ed_0
  • sysroot_linux-64=2.12=he073ed8_17
  • tbb=2021.11.0=h00ab1b0_1
  • tbb-devel=2021.11.0=h5ccd973_1
  • tk=8.6.13=noxft_h4845f30_101
  • tzdata=2024a=h0c530f3_0
  • urllib3=2.2.1=pyhd8ed1ab_0
  • utfcpp=4.0.5=ha770c72_0
  • vtk=9.2.6=qt_py312h1234567_220
  • vtk-base=9.2.6=qt_py312h1234567_220
  • vtk-io-ffmpeg=9.2.6=qt_py312h1234567_220
  • wheel=0.43.0=pyhd8ed1ab_1
  • wslink=1.12.4=pyhd8ed1ab_0
  • x264=1!164.3095=h166bdaf_2
  • x265=3.5=h924138e_3
  • xcb-util=0.4.0=hd590300_1
  • xcb-util-image=0.4.0=h8ee46fc_1
  • xcb-util-keysyms=0.4.0=h8ee46fc_1
  • xcb-util-renderutil=0.3.9=hd590300_1
  • xcb-util-wm=0.4.1=h8ee46fc_1
  • xkeyboard-config=2.41=hd590300_0
  • xorg-fixesproto=5.0=h7f98852_1002
  • xorg-kbproto=1.0.7=h7f98852_1002
  • xorg-libice=1.1.1=hd590300_0
  • xorg-libsm=1.2.4=h7391055_0
  • xorg-libx11=1.8.7=h8ee46fc_0
  • xorg-libxau=1.0.11=hd590300_0
  • xorg-libxdmcp=1.1.3=h7f98852_0
  • xorg-libxext=1.3.4=h0b41bf4_2
  • xorg-libxfixes=5.0.3=h7f98852_1004
  • xorg-libxrender=0.9.11=hd590300_0
  • xorg-libxt=1.3.0=hd590300_1
  • xorg-renderproto=0.11.1=h7f98852_1002
  • xorg-xextproto=7.3.0=h0b41bf4_1003
  • xorg-xf86vidmodeproto=2.3.1=h7f98852_1002
  • xorg-xproto=7.0.31=h7f98852_1007
  • xz=5.2.6=h166bdaf_0
  • yaml=0.2.5=h7f98852_2
  • yarl=1.9.4=py312h98912ed_0
  • zeromq=4.3.5=h59595ed_1
  • zfp=0.5.5=h9c3ff4c_8
  • zlib=1.2.13=hd590300_5
  • zlib-ng=2.0.7=h0b41bf4_0
  • zstd=1.5.5=hfc55251_0
    prefix: /home/gparish18/miniconda3/envs/fenicsx-env

The full error message traceback is

Traceback (most recent call last):
File “/home/gparish18/import numpy as np.py”, line 1, in
import dolfinx
^^^^^^^^^^^^^^
File “/home/gparish18/miniconda3/envs/fenics/lib/python3.12/site-packages/dolfinx/init.py”, line 40, in
from dolfinx import fem, geometry, graph, io, jit, la, log, mesh, nls, plot
File “/home/gparish18/miniconda3/envs/fenics/lib/python3.12/site-packages/dolfinx/fem/init.py”, line 11, in
from dolfinx.fem.assemble import (apply_lifting, assemble_matrix,
File “/home/gparish18/miniconda3/envs/fenics/lib/python3.12/site-packages/dolfinx/fem/assemble.py”, line 22, in
from dolfinx.fem.forms import Form
File “/home/gparish18/miniconda3/envs/fenics/lib/python3.12/site-packages/dolfinx/fem/forms.py”, line 17, in
from dolfinx import default_scalar_type, jit
File “/home/gparish18/miniconda3/envs/fenics/lib/python3.12/site-packages/dolfinx/jit.py”, line 17, in
import ffcx.codegeneration.jit
File “/home/gparish18/miniconda3/envs/fenics/lib/python3.12/site-packages/ffcx/codegeneration/jit.py”, line 21, in
import ffcx.naming
File “/home/gparish18/miniconda3/envs/fenics/lib/python3.12/site-packages/ffcx/naming.py”, line 16, in
from .element_interface import convert_element
File “/home/gparish18/miniconda3/envs/fenics/lib/python3.12/site-packages/ffcx/element_interface.py”, line 12, in
import basix.ufl
File “/home/gparish18/miniconda3/envs/fenics/lib/python3.12/site-packages/basix/ufl.py”, line 22, in
_basix.SobolevSpace.HInf: _ufl.sobolevspace.HInf,
^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module ‘ufl.sobolevspace’ has no attribute ‘HInf’

I installed dolfinx using the commands as listed on the fenics site:

conda create -n fenicsx-env
conda activate fenicsx-env
conda install -c conda-forge fenics-dolfinx mpich pyvista

Cant spot anything right away. Could you try

python3 -c "import ufl; print(ufl);print(ufl.__version__)"
and post the output?

the output is 2023.2.0

Just to give an update: this issue persists if using a standard python file in vscode (running the virtual ubuntu environment), but if I launch a Jupyter Notebook from the same ubuntu environment, I can run the Poisson example without issue.

I believe there is a persistent bug in vscode environment activation where it can corrupt some environment variables relevant to fenics. I’m not sure that’s relevant here or not, but you might try:

import os

for key in sorted(os.environ):
    if any(s in key for s in ("PYTHON", "CONDA", "FLAGS", "PATH")):
        print(f"{key}={os.environ[key]}")

in both environments and compare the difference.

You might also try a more comprehensive comparison running envreport in both environments to try to identify the difference.