Issue with gmshio import

I’m working with dolfinx via Google Colab, and I’m having some problems with dolfinx.io.gmshio.

I have gmsh installed in the notebook, and I’m trying to use the extract_geometry and extract_topology_and_markers methods. However, I get AttributeError: module 'dolfinx.io.gmshio' has no attribute 'extract_geometry'.

When calling gmshio._has_gmsh, the console returns False, and gmshio.__all__ only gives the list ['cell_perm_array', 'ufl_mesh'], where "extract_topology_and_markers", "extract_geometry", "model_to_mesh", "read_from_msh" are missing.

Here are the blocks I’m running on Colab:

%%capture
try:
    import dolfinx
except ImportError:
    !wget "https://fem-on-colab.github.io/releases/fenicsx-install-real.sh" -O "/tmp/fenicsx-install.sh" && bash "/tmp/fenicsx-install.sh"
    import dolfinx
!pip install -q gmsh
import gmsh
from dolfinx.io import gmshio

Any idea on why is this happening?
Thanks in advance.

As you can see from the source code: dolfinx/gmshio.py at main · FEniCS/dolfinx · GitHub _has_gmsh only checks if one can import gmsh.
What is the message you get if you call import gmsh?

Hi dokken,

When I run import gmsh the cell runs successfully. Moreover, running the lines manually for checking that one can import gmsh:

try:
    import gmsh
    _has_gmsh = True
except ModuleNotFoundError:
    _has_gmsh = False

gives _has_gmsh with _has_gmsh==True

I would have to ask @francesco-ballarin for his thoughts. I dont know much about how the installation process for colab is.

Okay. I’ll be looking forward to your answer. Thanks!

Make sure to install the gmsh provided by fem on colab BEFORE installing FEniCSx

1 Like