paraview-meshio-plugin.py not designed to run on windows or contains an error

In order to load a gmsh .msh file into paraview on windows 10,
I followed instructions from https://github.com/nschloe/meshio,
and attempted to load new plugin paraview_meshio_plugin.py .

I tried using both the intel python interpreter, and the python 3.8 interpreter from the windows store.
I made a passing attempt to use pvpython.exe, but the -m option appears to not be supported, so I didn’t fully pursue this path.

Both attempts lead to the same error message:

“\?\C:\Users…\share\paraview_5.8\paraview-meshio-plugin.py is either not designed to run on Windows or it contains an error. Try installing the program again using the original installation media or contact your system administrator or the software vendor for support. Error status 0x000012f.”

Running ParaView version 5.81
python library path C:\Program Files\ParaView 5.8.1-Windows-Python3.7-msvc2015-64bit\bin\lib

Additional information:

Line-by-line analysis of the plugin, using the ParaView python panel, suggests that the plugin crashes upon import of the meshio python package, when the meshio __init__.py function imports __about__.py :

try:
    # Python 3.8
    from importlib import metadata
except ImportError:
    import importlib_metadata as metadata

A Stackoverflow entry (https://stackoverflow.com/questions/59216175/importerror-cannot-import-name-metadata-from-importlib) suggests

pipenv install jsonschema==3.0.2

as a workaround. I haven’t found jsonschema installed in Paraview python.

I would appreciate any hints for a workaround for getting the meshio plugin to function.

I’ve never used this plugin from @nschloe, but I just want to mention that a new Gmsh plugin should be available in ParaView 5.10 (2021).

Perhaps I should remove those __version__ shenanigans.

I’ve looking into it and removing importlib would be too intrusive for meshio. I don’t think jsonschema is the problem either. Without an error message, it’s hard to tell.

Apologies for not fully reporting the error message earlier.

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
>>> from paraview.simple import *
>>> import meshio
Traceback (most recent call last):
  File "C:\Program Files\ParaView 5.8.1-Windows-Python3.7-msvc2015-64bit\bin\Lib\site-packages\meshio\__about__.py", line 3, in <module>
    from importlib import metadata
ImportError: cannot import name 'metadata' from 'importlib' (C:\Program Files\ParaView 5.8.1-Windows-Python3.7-msvc2015-64bit\bin\lib\importlib\__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Program Files\ParaView 5.8.1-Windows-Python3.7-msvc2015-64bit\bin\Lib\site-packages\meshio\__init__.py", line 1, in <module>
    from . import (
  File "C:\Program Files\ParaView 5.8.1-Windows-Python3.7-msvc2015-64bit\bin\Lib\site-packages\meshio\_cli\__init__.py", line 1, in <module>
    from ._ascii import ascii
  File "C:\Program Files\ParaView 5.8.1-Windows-Python3.7-msvc2015-64bit\bin\Lib\site-packages\meshio\_cli\_ascii.py", line 5, in <module>
    from .. import ansys, flac3d, gmsh, mdpa, ply, stl, vtk, vtu, xdmf
  File "C:\Program Files\ParaView 5.8.1-Windows-Python3.7-msvc2015-64bit\bin\Lib\site-packages\meshio\ansys\__init__.py", line 1, in <module>
    from ._ansys import read, write
  File "C:\Program Files\ParaView 5.8.1-Windows-Python3.7-msvc2015-64bit\bin\Lib\site-packages\meshio\ansys\_ansys.py", line 10, in <module>
    from ..__about__ import __version__
  File "C:\Program Files\ParaView 5.8.1-Windows-Python3.7-msvc2015-64bit\bin\Lib\site-packages\meshio\__about__.py", line 5, in <module>
    import importlib_metadata as metadata
ModuleNotFoundError: No module named 'importlib_metadata'
>>> 

Can you also post the contents of

C:\Program Files\ParaView 5.8.1-Windows-Python3.7-msvc2015-64bit\bin\Lib\site-packages\meshio\__about__.py

A couple of things …
First, the content of __about__.py

    # Python 3.8
    from importlib import metadata
except ImportError:
    import importlib_metadata as metadata

try:
    __version__ = metadata.version("meshio")
except Exception:
    __version__ = "unknown"

Second, I downloaded source, and added a couple of packages to C:\Program Files\ParaView 5.8.1-Windows-Python3.7-msvc2015-64bit\bin\Lib\site-packages

package importlib_metadata, extracting a directory from
https://github.com/python/importlib_metadata/tree/master/importlib_metadata

package zipp, placing into a directory the contents of
https://github.com/jaraco/zipp

At that point ```import meshio`` executed without complaint in the ParaView python window.
However attempting to load the plugin generates error messages:

Generic Warning: In C:\bbd\8fbebceb\build\superbuild\paraview\src\Remoting\ServerManagerPython\vtkPVPythonAlgorithmPlugin.cxx, line 187
Failed to load Python plugin:
Failed to call `paraview.detail.pythonalgorithm.load_plugin`.

Traceback (most recent call last):
  File "C:\Program Files\ParaView 5.8.1-Windows-Python3.7-msvc2015-64bit\bin\Lib\site-packages\paraview\detail\pythonalgorithm.py", line 509, in load_plugin
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Program Files\ParaView 5.8.1-Windows-Python3.7-msvc2015-64bit\share\paraview-meshio-plugin.py", line 14, in <module>
    paraview_plugin_version = meshio.__version__
AttributeError: module 'meshio' has no attribute '__version__'
ERROR: In C:\bbd\8fbebceb\build\superbuild\paraview\src\Remoting\Core\vtkPVPluginLoader.cxx, line 524
vtkPVPluginLoader (000002BB6EF08F90): %1 is not a valid Win32 application.

Thank you for your interest.

There’s a try: missing in your first code example, right?

If yes, I have no idea why the ImportError is not properly intercepted here.

Yes ! you are right that the first code example should begin with try:

I have the idea that it has to do with python packaging, but I don’t know what to make of the clues.
The readthedocs site for importlib_metadata (https://importlib-metadata.readthedocs.io/en/latest/) posts a release note:

## v2.0.0

2020-06-26

* `importlib_metadata`  no longer presents a  `__version__`  attribute. 
Consumers wishing to resolve the version of the package should query it directly 
with  `importlib_metadata.version('importlib-metadata')` . Closes #71.

Since pip is not available for ParaView python, I downloaded source and moved the appropriate code to site-packages by copy-paste. There may be an important step missing, which pip would normally perform.