To me it seems like you are trying to call gmsh -2 filename.geo as part of your python script.
To do so, you need to use os.system for such behavior, i.e.
from dolfin import *
import os
os.system("gmsh -2 filename.geo")
os.system("dolfin-convert filename.msh filename.xml")
mesh = Mesh("filename.xml")
Info : Running 'gmsh -2 filename.geo' [Gmsh 4.4.1, 1 node, max. 1 thread]
Info : Started on Thu Oct 21 15:18:03 2021
Info : Reading 'filename.geo'...
Info : Done reading 'filename.geo'
Info : Meshing 1D...
Info : Meshing curve 1 (Line)
Info : Meshing curve 2 (Line)
Info : Meshing curve 3 (Line)
Info : Meshing curve 4 (Line)
Info : Done meshing 1D (0.0024824 s)
Info : Meshing 2D...
Info : Meshing surface 1 (transfinite)
Info : Done meshing 2D (0.000872 s)
Info : 121 vertices 244 elements
Info : Writing 'filename.msh'...
Info : Done writing 'filename.msh'
Info : Stopped on Thu Oct 21 15:18:03 2021
Converting from Gmsh format (.msh, .gmsh) to DOLFIN XML format mbseidel@DESKTOP-NPRJ0E1:/mnt/c/users/matheus seidel/documents$
File "/usr/bin/dolfin-convert", line 132, in <module>
main(sys.argv[1:])
File "/usr/bin/dolfin-convert", line 79, in main
meshconvert.convert2xml(ifilename, ofilename, iformat=iformat)
File "/usr/lib/python3/dist-packages/dolfin_utils/meshconvert/meshconvert.py", line 1301, in convert2xml
convert(ifilename, XmlHandler(ofilename), iformat=iformat)
File "/usr/lib/python3/dist-packages/dolfin_utils/meshconvert/meshconvert.py", line 1322, in convert
gmsh2xml(ifilename, handler)
File "/usr/lib/python3/dist-packages/dolfin_utils/meshconvert/meshconvert.py", line 271, in gmsh2xml
num_elements = int(line)
ValueError: invalid literal for int() with base 10: '9 244 1 244\n' Traceback (most recent call last):
File "NS_test.py", line 17, in <module>
mesh = Mesh("filename.xml")
RuntimeError:
*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
*** fenics-support@googlegroups.com
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error: Unable to read data from XML file.
*** Reason: Not a DOLFIN XML file.
*** Where: This error was encountered inside XMLFile.cpp.
*** Process: 0
***
*** DOLFIN version: 2019.2.0.dev0
*** Git changeset: unknown
*** -------------------------------------------------------------------------