Cannot import name 'default_scalar_type' from 'dolfinx'

I am using a Windows installation of Dolfinx (FeNICSx) using docker containers. I created a container using the following code:

docker run --init -p 8888:8888 -v %cd%:/root/shared --name=dolfinx_test0 dolfinx/lab:latest

I created a jupyter notebook under this container. When I run the code from dolfinx import default_scalar_type, I am getting the following error:

ImportError Traceback (most recent call last)
Cell In [4], line 6
3 from dolfinx.fem import (Constant, Function, FunctionSpace, assemble_scalar, form, locate_dofs_topological)
4 from dolfinx.fem.petsc import (LinearProblem, assemble_vector, assemble_matrix, create_vector,
5 apply_lifting, set_bc)
----> 6 from dolfinx import default_scalar_type
7 from import XDMFFile
8 from dolfinx.mesh import create_rectangle, locate_entities, locate_entities_boundary, meshtags, CellType

ImportError: cannot import name ‘default_scalar_type’ from ‘dolfinx’ (/usr/local/dolfinx-real/lib/python3.10/dist-packages/dolfinx/

Rest of the lines in the above code are running without a problem. I am getting the same error when I run from dolfinx.plot import vtk_mesh. I am running the below dolfinx version 72c70a59b8bed7cc5caa4c68a84182c9c4be87cf

Can someone please help with this?

The latest tag is no longer updated, please use any of dolfinx/lab:nighlty, dolfinx/lab:stable, dolfinx/lab:v0.7.0 to get dolfinx.default_scalar_type, as it was introduced in between v0.6.0 and v0.7.0.


It worked. Thank you!

hi, can you pls elaborate what do you mean by your solution? how so i implement that? what do i use instead of “from dolfinx import log, default_scalar_type”

1 Like

What version of DOLFINx are you running?


בתאריך יום ג׳, 21 בנוב׳ 2023 ב-23:34 מאת Jorgen Dokken via FEniCS Project <>:

Then you can simply use

from petsc4py import PETSc
default_scalar_type = PETSc.ScalarType

Yes that help, thank you!

בתאריך יום ג׳, 21 בנוב׳ 2023 ב-23:56 מאת Jorgen Dokken via FEniCS Project <>:

I already have dolfinx ,installation like appana_3 with v0.6.0 , how can i update the version

Update your docker image by pulling docker pull and create a new docker container with it

Excuse me, are these two completely equivalent? Because I found that they are all used in the tutorial and appear to have the same effect。

It should be the same if petsc4py is imported dolfinx/python/dolfinx/ at main · FEniCS/dolfinx · GitHub

Thanks very much for your reply and the source code link you provided.