AttributeError: `ufl.Constant` when running Python 3.13 through conda

Hey there,

I am trying to get started on fenics-dolfinx and after half a day was finally able to install it via conda.
However, when I try to run import dolfinx I get the following error.

>>> import dolfinx
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    import dolfinx
  File "/home/vincent/anaconda3/envs/fenicsx-env/lib/python3.13/site-packages/dolfinx/__init__.py", line 32, in <module>
    from dolfinx import fem, geometry, graph, io, jit, la, log, mesh, nls, plot, utils
  File "/home/vincent/anaconda3/envs/fenicsx-env/lib/python3.13/site-packages/dolfinx/fem/__init__.py", line 18, in <module>
    from dolfinx.fem.assemble import (
    ...<7 lines>...
    )
  File "/home/vincent/anaconda3/envs/fenicsx-env/lib/python3.13/site-packages/dolfinx/fem/assemble.py", line 23, in <module>
    from dolfinx.fem.forms import Form
  File "/home/vincent/anaconda3/envs/fenicsx-env/lib/python3.13/site-packages/dolfinx/fem/forms.py", line 23, in <module>
    from dolfinx.fem.function import FunctionSpace
  File "/home/vincent/anaconda3/envs/fenicsx-env/lib/python3.13/site-packages/dolfinx/fem/function.py", line 29, in <module>
    class Constant(ufl.Constant):
                   ^^^^^^^^^^^^
AttributeError: module 'ufl' has no attribute 'Constant'

I am not really sure what to do about it.
I tried to look it up in the ufl API here and regarding that, it should be ufl.constant.Constant. So I was wondering whether this is a bug in dolfinx or am I messing up versions of ufl and dolfinx that are not intended to be used.
But for the latter I am a bit puzzled, since I did not specifically install ufl via pip or so, but it was just done, when I install dolfinx.

Any advices are appreciated.

Thanks
Vincent

ufl.constant.Constant is also part of the ufl init file: ufl/ufl/__init__.py at main Ā· FEniCS/ufl Ā· GitHub
meaning that it gets imported when you call import ufl.

Could you check that there is no folder called ufl in your current directory?
Secondly, could you do a conda env export so that we can see what versions you have installed/

1 Like

I don’t see any ufl folder when searching for it.

The conda env export gives the following output

name: fenicsx-env
channels:
  - conda-forge
  - defaults
dependencies:
  - _libgcc_mutex=0.1=conda_forge
  - _openmp_mutex=4.5=2_kmp_llvm
  - aiohappyeyeballs=2.4.3=pyhd8ed1ab_0
  - aiohttp=3.10.10=py313h8060acc_0
  - aiosignal=1.3.1=pyhd8ed1ab_0
  - alsa-lib=1.2.12=h4ab18f5_0
  - aom=3.9.1=hac33072_0
  - asttokens=2.4.1=pyhd8ed1ab_0
  - attrs=24.2.0=pyh71513ae_0
  - binutils_impl_linux-64=2.43=h4bf12b8_2
  - binutils_linux-64=2.43=h4852527_2
  - blosc=1.21.6=hef167b5_0
  - brotli=1.1.0=hb9d3cd8_2
  - brotli-bin=1.1.0=hb9d3cd8_2
  - brotli-python=1.1.0=py313h46c70d0_2
  - bzip2=1.0.8=h4bc722e_7
  - c-ares=1.34.3=heb4867d_0
  - c-blosc2=2.15.1=hc57e6cf_0
  - ca-certificates=2024.8.30=hbcca054_0
  - cairo=1.18.0=hebfffa5_3
  - certifi=2024.8.30=pyhd8ed1ab_0
  - cffi=1.17.1=py313hfab6e84_0
  - charset-normalizer=3.4.0=pyhd8ed1ab_0
  - comm=0.2.2=pyhd8ed1ab_0
  - contourpy=1.3.0=py313h33d0bda_2
  - cycler=0.12.1=pyhd8ed1ab_0
  - dav1d=1.2.1=hd590300_0
  - dbus=1.13.6=h5008d03_3
  - debugpy=1.8.8=py313h46c70d0_0
  - decorator=5.1.1=pyhd8ed1ab_0
  - double-conversion=3.3.0=h59595ed_0
  - eigen=3.4.0=h00ab1b0_0
  - exceptiongroup=1.2.2=pyhd8ed1ab_0
  - executing=2.1.0=pyhd8ed1ab_0
  - expat=2.6.4=h5888daf_0
  - fenics-basix=0.9.0=py313h867a91d_2
  - fenics-basix-nanobind-abi=0.2.1.13=h6c05e69_2
  - fenics-dolfinx=0.9.0=py313h29c2d7e_106
  - fenics-ffcx=0.9.0=pyh2e48890_0
  - fenics-libbasix=0.9.0=h7cb7ce6_2
  - fenics-libdolfinx=0.9.0=h9e81c43_106
  - fenics-ufcx=0.9.0=hb7f7608_0
  - fenics-ufl=2024.2.0=pyhd8ed1ab_0
  - ffmpeg=7.1.0=gpl_h8657690_700
  - fftw=3.3.10=mpi_mpich_hbcf76dd_10
  - fmt=11.0.2=h434a139_0
  - 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_3
  - fontconfig=2.15.0=h7e30c49_1
  - fonts-conda-ecosystem=1=0
  - fonts-conda-forge=1=0
  - fonttools=4.54.1=py313h8060acc_1
  - freetype=2.12.1=h267a509_2
  - fribidi=1.0.10=h36c2ea0_0
  - frozenlist=1.5.0=py313h536fd9c_0
  - gcc_impl_linux-64=13.3.0=hfea6d02_1
  - gcc_linux-64=13.3.0=hc28eda2_5
  - gl2ps=1.4.2=hae5d5c5_1
  - glew=2.1.0=h9c3ff4c_2
  - gmp=6.3.0=hac33072_2
  - graphite2=1.3.13=h59595ed_1003
  - h2=4.1.0=pyhd8ed1ab_0
  - harfbuzz=9.0.0=hda332d3_1
  - hdf4=4.2.15=h2a13503_7
  - hdf5=1.14.4=mpi_mpich_h7f58efa_3
  - hpack=4.0.0=pyh9f0ad1d_0
  - hyperframe=6.0.1=pyhd8ed1ab_0
  - hypre=2.32.0=mpi_mpich_h2e71eac_1
  - icu=75.1=he02047a_0
  - idna=3.10=pyhd8ed1ab_0
  - importlib-metadata=8.5.0=pyha770c72_0
  - ipykernel=6.29.5=pyh3099207_0
  - ipython=8.29.0=pyh707e725_0
  - jedi=0.19.2=pyhff2d567_0
  - jsoncpp=1.9.6=h84d6215_0
  - jupyter_client=8.6.3=pyhd8ed1ab_0
  - jupyter_core=5.7.2=pyh31011fe_1
  - kahip=3.16=h2fbc463_4
  - kernel-headers_linux-64=3.10.0=he073ed8_18
  - keyutils=1.6.1=h166bdaf_0
  - kiwisolver=1.4.7=py313h33d0bda_0
  - krb5=1.21.3=h659f571_0
  - lame=3.100=h166bdaf_1003
  - lcms2=2.16=hb7c19ff_0
  - ld_impl_linux-64=2.43=h712a8e2_2
  - lerc=4.0.0=h27087fc_0
  - libabseil=20240722.0=cxx17_h5888daf_1
  - libadios2=2.10.2=mpi_mpich_h4f42236_0
  - libaec=1.1.3=h59595ed_0
  - libass=0.17.3=h1dc1e6a_0
  - libblas=3.9.0=25_linux64_openblas
  - libboost=1.86.0=hb8260a3_2
  - libboost-devel=1.86.0=h1a2810e_2
  - libboost-headers=1.86.0=ha770c72_2
  - libbrotlicommon=1.1.0=hb9d3cd8_2
  - libbrotlidec=1.1.0=hb9d3cd8_2
  - libbrotlienc=1.1.0=hb9d3cd8_2
  - libcblas=3.9.0=25_linux64_openblas
  - libclang-cpp19.1=19.1.3=default_hb5137d0_0
  - libclang13=19.1.3=default_h9c6a7e4_0
  - libcups=2.3.3=h4637d8d_4
  - libcurl=8.10.1=hbbe4b11_0
  - libdeflate=1.22=hb9d3cd8_0
  - libdrm=2.4.123=hb9d3cd8_0
  - libedit=3.1.20191231=he28a2e2_2
  - libegl=1.7.0=ha4b6fd6_0
  - libev=4.33=hd590300_2
  - libexpat=2.6.4=h5888daf_0
  - libffi=3.4.2=h7f98852_5
  - libgcc=14.2.0=h77fa898_1
  - libgcc-devel_linux-64=13.3.0=h84ea5a7_101
  - libgcc-ng=14.2.0=h69a702a_1
  - libgfortran=14.2.0=h69a702a_1
  - libgfortran-ng=14.2.0=h69a702a_1
  - libgfortran5=14.2.0=hd5240d6_1
  - libgl=1.7.0=ha4b6fd6_0
  - libglib=2.82.2=h2ff4ddf_0
  - libglu=9.0.0=ha6d2627_1004
  - libglvnd=1.7.0=ha4b6fd6_0
  - libglx=1.7.0=ha4b6fd6_0
  - libgomp=14.2.0=h77fa898_1
  - libhwloc=2.11.2=default_h0d58e46_1001
  - libiconv=1.17=hd590300_2
  - libjpeg-turbo=3.0.0=hd590300_1
  - liblapack=3.9.0=25_linux64_openblas
  - libllvm19=19.1.3=ha7bfdaf_0
  - libmpdec=4.0.0=h4bc722e_0
  - libnetcdf=4.9.2=nompi_h2564987_115
  - libnghttp2=1.64.0=h161d5f1_0
  - libogg=1.3.5=h4ab18f5_0
  - libopenblas=0.3.28=openmp_hd680484_1
  - libopenvino=2024.4.0=hac27bb2_2
  - libopenvino-auto-batch-plugin=2024.4.0=h4d9b6c2_2
  - libopenvino-auto-plugin=2024.4.0=h4d9b6c2_2
  - libopenvino-hetero-plugin=2024.4.0=h3f63f65_2
  - libopenvino-intel-cpu-plugin=2024.4.0=hac27bb2_2
  - libopenvino-intel-gpu-plugin=2024.4.0=hac27bb2_2
  - libopenvino-intel-npu-plugin=2024.4.0=hac27bb2_2
  - libopenvino-ir-frontend=2024.4.0=h3f63f65_2
  - libopenvino-onnx-frontend=2024.4.0=h5c8f2c3_2
  - libopenvino-paddle-frontend=2024.4.0=h5c8f2c3_2
  - libopenvino-pytorch-frontend=2024.4.0=h5888daf_2
  - libopenvino-tensorflow-frontend=2024.4.0=h6481b9d_2
  - libopenvino-tensorflow-lite-frontend=2024.4.0=h5888daf_2
  - libopus=1.3.1=h7f98852_1
  - libpciaccess=0.18=hd590300_0
  - libpng=1.6.44=hadc24fc_0
  - libpq=16.4=h2d7952a_3
  - libprotobuf=5.28.2=h5b01275_0
  - libptscotch=7.0.5=h49f1bd8_2
  - libsanitizer=13.3.0=heb74ff8_1
  - libscotch=7.0.5=h2fc2182_2
  - libsodium=1.0.20=h4ab18f5_0
  - libsqlite=3.47.0=hadc24fc_1
  - libssh2=1.11.0=h0841786_0
  - libstdcxx=14.2.0=hc0a3c3a_1
  - libstdcxx-ng=14.2.0=h4852527_1
  - libtheora=1.1.1=h4ab18f5_1006
  - libtiff=4.7.0=he137b08_1
  - libuuid=2.38.1=h0b41bf4_0
  - libva=2.22.0=h8a09558_1
  - libvorbis=1.3.7=h9c3ff4c_0
  - libvpx=1.14.1=hac33072_0
  - libwebp-base=1.4.0=hd590300_0
  - libxcb=1.16=hb9d3cd8_1
  - libxkbcommon=1.7.0=h2c5496b_1
  - libxml2=2.13.4=hb346dea_2
  - libzip=1.11.2=h6991a6a_0
  - libzlib=1.3.1=hb9d3cd8_2
  - llvm-openmp=19.1.3=h024ca30_0
  - loguru=0.7.2=py313h78bf25f_2
  - lz4-c=1.9.4=hcb278e6_0
  - matplotlib-base=3.9.2=py313h129903b_2
  - matplotlib-inline=0.1.7=pyhd8ed1ab_0
  - metis=5.1.0=hd0bcaf9_1007
  - mpfr=4.2.1=h90cbb55_3
  - mpi=1.0.1=mpich
  - mpi4py=4.0.1=py313h7246b6a_0
  - mpich=4.2.3=h670b19f_100
  - msgpack-python=1.1.0=py313h33d0bda_0
  - multidict=6.1.0=py313h8060acc_1
  - mumps-include=5.7.3=ha770c72_5
  - mumps-mpi=5.7.3=hb595572_5
  - munkres=1.1.4=pyh9f0ad1d_0
  - mysql-common=9.0.1=h266115a_2
  - mysql-libs=9.0.1=he0572af_2
  - ncurses=6.5=he02047a_1
  - nest-asyncio=1.6.0=pyhd8ed1ab_0
  - nlohmann_json=3.11.3=he02047a_1
  - numpy=2.1.3=py313h4bf6692_0
  - ocl-icd=2.3.2=hd590300_1
  - openh264=2.4.1=h59595ed_0
  - openjpeg=2.5.2=h488ebb8_0
  - openssl=3.4.0=hb9d3cd8_0
  - packaging=24.1=pyhd8ed1ab_0
  - parmetis=4.0.3=hc7bef4e_1007
  - parso=0.8.4=pyhd8ed1ab_0
  - pcre2=10.44=hba22ea6_2
  - petsc=3.22.1=real_hddfc770_101
  - petsc4py=3.22.1=py313h159419d_0
  - pexpect=4.9.0=pyhd8ed1ab_0
  - pickleshare=0.7.5=py_1003
  - pillow=10.4.0=py313hc9074d1_1
  - pip=24.3.1=pyh145f28c_0
  - pixman=0.43.2=h59595ed_0
  - pkg-config=0.29.2=h4bc722e_1009
  - platformdirs=4.3.6=pyhd8ed1ab_0
  - pooch=1.8.2=pyhd8ed1ab_0
  - proj=9.5.0=h12925eb_0
  - prompt-toolkit=3.0.48=pyha770c72_0
  - propcache=0.2.0=py313h536fd9c_2
  - psutil=6.1.0=py313h536fd9c_0
  - pthread-stubs=0.4=hb9d3cd8_1002
  - ptyprocess=0.7.0=pyhd3deb0d_0
  - pugixml=1.14=h59595ed_0
  - pure_eval=0.2.3=pyhd8ed1ab_0
  - pycparser=2.22=pyhd8ed1ab_0
  - pygments=2.18.0=pyhd8ed1ab_0
  - pyparsing=3.2.0=pyhd8ed1ab_1
  - pysocks=1.7.1=pyha2e5f31_6
  - python=3.13.0=h9ebbce0_100_cp313
  - python-dateutil=2.9.0=pyhd8ed1ab_0
  - python_abi=3.13=5_cp313
  - pyvista=0.44.1=pyhd8ed1ab_0
  - pyzmq=26.2.0=py313h8e95178_3
  - qhull=2020.2=h434a139_5
  - qt6-main=6.7.2=hadfd74e_5
  - readline=8.2=h8228510_1
  - requests=2.32.3=pyhd8ed1ab_0
  - scalapack=2.2.0=h7e29ba8_4
  - scooby=0.10.0=pyhd8ed1ab_0
  - setuptools=75.3.0=pyhd8ed1ab_0
  - six=1.16.0=pyh6c4a22f_0
  - slepc=3.22.1=real_h754b140_302
  - slepc4py=3.22.1=py313h01fd916_1
  - snappy=1.2.1=ha2e4443_0
  - spdlog=1.14.1=hed91bc2_1
  - sqlite=3.47.0=h9eae976_1
  - stack_data=0.6.2=pyhd8ed1ab_0
  - suitesparse=7.8.3=hb42a789_0
  - superlu=5.2.2=h00795ac_0
  - superlu_dist=9.1.0=h0804ebd_0
  - svt-av1=2.2.1=h5888daf_0
  - sysroot_linux-64=2.17=h4a8ded7_18
  - tbb=2022.0.0=hceb3a55_0
  - tbb-devel=2022.0.0=h1f99690_0
  - tk=8.6.13=noxft_h4845f30_101
  - tornado=6.4.1=py313h536fd9c_1
  - traitlets=5.14.3=pyhd8ed1ab_0
  - typing-extensions=4.12.2=hd8ed1ab_0
  - typing_extensions=4.12.2=pyha770c72_0
  - tzdata=2024b=hc8b5060_0
  - urllib3=2.2.3=pyhd8ed1ab_0
  - utfcpp=4.0.6=h005c6e1_0
  - vtk=9.3.1=qt_py313h3d4e8c9_209
  - vtk-base=9.3.1=qt_py313hcd96e40_209
  - vtk-io-ffmpeg=9.3.1=qt_py313he1e5eab_209
  - wayland=1.23.1=h3e06ad9_0
  - wayland-protocols=1.37=hd8ed1ab_0
  - wcwidth=0.2.13=pyhd8ed1ab_0
  - wslink=2.2.1=pyhd8ed1ab_0
  - x264=1!164.3095=h166bdaf_2
  - x265=3.5=h924138e_3
  - xcb-util=0.4.1=hb711507_2
  - xcb-util-cursor=0.1.5=hb9d3cd8_0
  - xcb-util-image=0.4.0=hb711507_2
  - xcb-util-keysyms=0.4.1=hb711507_0
  - xcb-util-renderutil=0.3.10=hb711507_0
  - xcb-util-wm=0.4.2=hb711507_0
  - xkeyboard-config=2.42=h4ab18f5_0
  - xorg-fixesproto=5.0=hb9d3cd8_1003
  - xorg-inputproto=2.3.2=hb9d3cd8_1003
  - xorg-kbproto=1.0.7=hb9d3cd8_1003
  - xorg-libice=1.1.1=hb9d3cd8_1
  - xorg-libsm=1.2.4=he73a12e_1
  - xorg-libx11=1.8.9=hb711507_1
  - xorg-libxau=1.0.11=hb9d3cd8_1
  - xorg-libxdmcp=1.1.5=hb9d3cd8_0
  - xorg-libxext=1.3.4=h0b41bf4_2
  - xorg-libxfixes=5.0.3=h7f98852_1004
  - xorg-libxi=1.7.10=h4bc722e_1
  - xorg-libxrender=0.9.11=hd590300_0
  - xorg-libxt=1.3.0=hd590300_1
  - xorg-libxtst=1.2.5=h4bc722e_0
  - xorg-libxxf86vm=1.1.5=hb9d3cd8_2
  - xorg-recordproto=1.14.2=hb9d3cd8_1003
  - xorg-renderproto=0.11.1=hb9d3cd8_1003
  - xorg-xextproto=7.3.0=hb9d3cd8_1004
  - xorg-xproto=7.0.31=hb9d3cd8_1008
  - xz=5.2.6=h166bdaf_0
  - yaml=0.2.5=h7f98852_2
  - yarl=1.16.0=py313h536fd9c_0
  - zeromq=4.3.5=h3b0a872_6
  - zfp=0.5.5=h9c3ff4c_8
  - zipp=3.21.0=pyhd8ed1ab_0
  - zlib=1.3.1=hb9d3cd8_2
  - zlib-ng=2.2.2=h5888daf_0
  - zstandard=0.23.0=py313h80202fe_1
  - zstd=1.5.6=ha6fb4c9_0
  - pip:
      - h5py==3.12.1
      - tqdm==4.67.0
prefix: /home/vincent/anaconda3/envs/fenicsx-env

What happens if you run python3 -c "import ufl; print(ufl); ufl.Constant"?

Get the same error,

<module 'ufl' (namespace) from ['/home/vincent/anaconda3/envs/fenicsx-env/lib/python3.13/site-packages/ufl']>
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import ufl; print(ufl); ufl.Constant
                            ^^^^^^^^^^^^
AttributeError: module 'ufl' has no attribute 'Constant'

I can reproduce this with python3.13:

name: test_dx_13
channels:
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=conda_forge
  - _openmp_mutex=4.5=2_gnu
  - binutils_impl_linux-64=2.43=h4bf12b8_2
  - binutils_linux-64=2.43=h4852527_2
  - blis=0.9.0=h4ab18f5_2
  - bzip2=1.0.8=h4bc722e_7
  - c-ares=1.34.3=heb4867d_0
  - c-blosc2=2.15.1=hc57e6cf_0
  - ca-certificates=2024.8.30=hbcca054_0
  - cffi=1.17.1=py313hfab6e84_0
  - fenics-basix=0.9.0=py313h867a91d_2
  - fenics-basix-nanobind-abi=0.2.1.13=h6c05e69_2
  - fenics-dolfinx=0.9.0=py313h29c2d7e_106
  - fenics-ffcx=0.9.0=pyh2e48890_0
  - fenics-libbasix=0.9.0=h7cb7ce6_2
  - fenics-libdolfinx=0.9.0=h9e81c43_106
  - fenics-ufcx=0.9.0=hb7f7608_0
  - fenics-ufl=2024.2.0=pyhd8ed1ab_0
  - fftw=3.3.10=mpi_mpich_hbcf76dd_10
  - fmt=11.0.2=h434a139_0
  - gcc_impl_linux-64=13.3.0=hfea6d02_1
  - gcc_linux-64=13.3.0=hc28eda2_5
  - gmp=6.3.0=hac33072_2
  - hdf5=1.14.4=mpi_mpich_h7f58efa_3
  - hypre=2.32.0=mpi_mpich_h2e71eac_1
  - icu=75.1=he02047a_0
  - kahip=3.16=h2fbc463_4
  - kernel-headers_linux-64=3.10.0=he073ed8_18
  - keyutils=1.6.1=h166bdaf_0
  - krb5=1.21.3=h659f571_0
  - ld_impl_linux-64=2.43=h712a8e2_2
  - libadios2=2.10.2=mpi_mpich_h4f42236_0
  - libaec=1.1.3=h59595ed_0
  - libblas=3.9.0=25_linux64_blis
  - libboost=1.86.0=hb8260a3_2
  - libboost-devel=1.86.0=h1a2810e_2
  - libboost-headers=1.86.0=ha770c72_2
  - libcblas=3.9.0=25_linux64_blis
  - libcurl=8.10.1=hbbe4b11_0
  - libedit=3.1.20191231=he28a2e2_2
  - libev=4.33=hd590300_2
  - libexpat=2.6.4=h5888daf_0
  - libffi=3.4.2=h7f98852_5
  - libgcc=14.2.0=h77fa898_1
  - libgcc-devel_linux-64=13.3.0=h84ea5a7_101
  - libgcc-ng=14.2.0=h69a702a_1
  - libgfortran=14.2.0=h69a702a_1
  - libgfortran-ng=14.2.0=h69a702a_1
  - libgfortran5=14.2.0=hd5240d6_1
  - libgomp=14.2.0=h77fa898_1
  - libhwloc=2.11.2=default_h0d58e46_1001
  - libiconv=1.17=hd590300_2
  - liblapack=3.9.0=8_h3b12eaf_netlib
  - libmpdec=4.0.0=h4bc722e_0
  - libnghttp2=1.64.0=h161d5f1_0
  - libpng=1.6.44=hadc24fc_0
  - libptscotch=7.0.5=h49f1bd8_2
  - libsanitizer=13.3.0=heb74ff8_1
  - libscotch=7.0.5=h2fc2182_2
  - libsodium=1.0.20=h4ab18f5_0
  - libsqlite=3.47.0=hadc24fc_1
  - libssh2=1.11.0=h0841786_0
  - libstdcxx=14.2.0=hc0a3c3a_1
  - libstdcxx-ng=14.2.0=h4852527_1
  - libuuid=2.38.1=h0b41bf4_0
  - libxml2=2.13.4=hb346dea_2
  - libzlib=1.3.1=hb9d3cd8_2
  - lz4-c=1.9.4=hcb278e6_0
  - metis=5.1.0=hd0bcaf9_1007
  - mpfr=4.2.1=h90cbb55_3
  - mpi=1.0.1=mpich
  - mpi4py=4.0.1=py313h7246b6a_0
  - mpich=4.2.3=h670b19f_100
  - mumps-include=5.7.3=ha770c72_5
  - mumps-mpi=5.7.3=hb595572_5
  - ncurses=6.5=he02047a_1
  - numpy=2.1.3=py313h4bf6692_0
  - openssl=3.4.0=hb9d3cd8_0
  - parmetis=4.0.3=hc7bef4e_1007
  - petsc=3.22.1=real_hddfc770_101
  - petsc4py=3.22.1=py313h159419d_0
  - pip=24.3.1=pyh145f28c_0
  - pkg-config=0.29.2=h4bc722e_1009
  - pugixml=1.14=h59595ed_0
  - pycparser=2.22=pyhd8ed1ab_0
  - python=3.13.0=h9ebbce0_100_cp313
  - python_abi=3.13=5_cp313
  - readline=8.2=h8228510_1
  - scalapack=2.2.0=h7e29ba8_4
  - setuptools=75.3.0=pyhd8ed1ab_0
  - slepc=3.22.1=real_h754b140_302
  - slepc4py=3.22.1=py313h01fd916_1
  - spdlog=1.14.1=hed91bc2_1
  - suitesparse=7.8.3=hb42a789_0
  - superlu=5.2.2=h00795ac_0
  - superlu_dist=9.1.0=h0804ebd_0
  - sysroot_linux-64=2.17=h4a8ded7_18
  - tbb=2022.0.0=hceb3a55_0
  - tk=8.6.13=noxft_h4845f30_101
  - tzdata=2024b=hc8b5060_0
  - xz=5.2.6=h166bdaf_0
  - yaml=0.2.5=h7f98852_2
  - zeromq=4.3.5=h3b0a872_6
  - zfp=0.5.5=h9c3ff4c_8
  - zlib=1.3.1=hb9d3cd8_2
  - zlib-ng=2.2.2=h5888daf_0
  - zstd=1.5.6=ha6fb4c9_0
prefix: /home/dokken/src/mambaforge/envs/test_dx_13

For now you could try using python3.12, as it works for me (when testing with conda locally).

Is there a way to downgrade python without making a new conda environment (not really used conda before).

I don’t think so.

It should be very hard to create a new env.

conda deactivate 
conda env remove -n fenicsx-env
conda create -n fenicsx-env python=3.12 fenics-dolfinx
conda activate fenicsx-env

I guess additionally one wants to specify the channel to be conda-forge right?

But this then seems to work.

Thanks!

Yes, depending on your conda installation you would have to specify -c conda-forge.

Thanks.

Not related to the installation issue, but to ufl.
After having it installed, I tried to build a FiniteElement, similar to the manual.

But for the code

import ufl
from ulf import *
element = FiniteElement("Lagrange", interval, 3)

I get the error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'FiniteElement' is not defined

If I try to call the FiniteElement class directly,

ufl.finiteelement.FiniteElement("Lagrange", interval, 3)

It say I am missing some arguments, which I don`t know yet how to construct.

What is the explanation for this behaviour?

This is the manual for the ā€œoldā€ ufl, that is compatible with legacy DOLFIN. For an introduction to DOLFINx, I would suggest starting with:
FEniCS workshop — FEniCS Workshop,
The FEniCSx tutorial — FEniCSx tutorial,
or Demos — DOLFINx 0.9.0 documentation

Ahh, thanks a lot.

I will work through the tutorials you pointed at.

I tried this env in docker run --rm -it --platform linux/amd64 condaforge/miniforge3 image and it works fine:

python3 -c "import ufl; print(ufl); ufl.Constant"
<module 'ufl' from '/opt/conda/envs/test-env/lib/python3.13/site-packages/ufl/__init__.py'>

conda env export is identical.

The namespace package output suggests that site-packages/ufl/__init__.py got deleted somehow, which is weird because it’s in the package.

Can you share:

  • conda info
  • ls -l /home/vincent/anaconda3/pkgs/fenics-ufl-2024.2.0-pyhd8ed1ab_0/site-packages/ufl (aka $CONDA_ROOT/pkgs/…)
  • ls -l /home/vincent/anaconda3/envs/fenicsx-env/lib/python3.13/site-packages/ufl (aka $CONDA_PREFIX/lib/…)

It seems like your local install of the fenics-ufl package got corrupted somehow. Perhaps reinstalling it would fix it as well:

conda install --force-reinstall fenics-ufl

Thanks for your answer.
I followed the suggestion above and already removed the old conda environment.
Since I am anyhow not forced to use python 3.13, it works fine for me now with python 3.12.

I tried re-installing it today with Python 3.13 and it now runs with no issue.

A glitch in the matrix?

very weird that you both managed to see this at the same time in the same Python version. It does point to a possible bug in conda or mamba noarch package installation, but if it’s working now and everything is up to date, let’s hope it was a transient problem that’s been solved :crossed_fingers: .