I disagree with your claim. All the code I have posted above is using msh 4.1.
The following illustrates a use case with the latest version of GMSH. Starting from a clean ubuntu 20.04 environment using docker:
docker run -ti -v $PWD:/home/shared -w /home/shared --rm ubuntu:20.04
Installation instructions in docker
apt-get update -qq
apt-get install -y -qq software-properties-common python3-pip libglu1 libxrender1 libcursor1 libxft2 libxinerama1
add-apt-repository -y ppa:fenics-packages/fenics
apt install -y --no-install-recommends fenics
pip3 -q install --upgrade sympy
pip3 install gmsh
export HDF5_MPI="ON"
export CC=mpicc
export HDF5_DIR="/usr/lib/x86_64-linux-gnu/hdf5/openmpi/"
pip3 install --no-binary=h5py h5py meshio
# Download tutorial_t1.geo from https://gitlab.onelab.info/gmsh/gmsh/-/blob/master/tutorial/t1.geo
/usr/local/lib/python3.8/site-packages/gmsh-4.8.0-Linux64-sdk/bin/gmsh -2 tutorial_t1.geo
The mesh, as shown above has the following msh format:
$MeshFormat
4.1 0 8
$EndMeshFormat
$PhysicalNames
1
2 6 "My surface"
$EndPhysicalNames
$Entities
# ....
The following code runs without error:
import numpy
import meshio
mesh_from_file = meshio.read("tutorial_t1.msh")
def create_mesh(mesh, cell_type, prune_z=False):
cells = numpy.vstack(
[cell.data for cell in mesh.cells if cell.type == cell_type])
# Remove z-coordinates from mesh if we have a 2D cell and all points have the same third coordinate
points = mesh.points
if prune_z:
points = points[:, :2]
mesh_new = meshio.Mesh(points=points, cells={cell_type: cells})
return mesh_new
triangle_mesh = create_mesh(mesh_from_file, "triangle")
meshio.write("mesh_3d.xdmf", triangle_mesh)