pythonlinuxlibvirt

"ImportError: cannot import name 'metadata'" when compile libvirt


When I compiling libvirt code from github,There are the following errors:

[395/1071] Generating 'docs/committer-guidelines.html.p/committer-guidelines.html.in'.
FAILED: docs/committer-guidelines.html.p/committer-guidelines.html.in
/usr/bin/meson --internal exe --capture docs/committer-guidelines.html.p/committer-guidelines.html.in -- /usr/local/bin/rst2html5 --stylesheet= --strict ../docs/committer-guidelines.rst
Traceback (most recent call last):
  File "/usr/local/bin/rst2html5", line 7, in <module>
    from rst2html5_ import main
  File "/usr/local/lib/python3.6/site-packages/rst2html5_.py", line 17, in <module>
    from rst2html5 import HTML5Writer  # noqa E402
  File "/usr/local/lib/python3.6/site-packages/rst2html5/__init__.py", line 4, in <module>
    from importlib import metadata
ImportError: cannot import name 'metadata'
[422/1071] Compiling C object src/conf/libvirt_conf.a.p/domain_conf.c.o
ninja: build stopped: subcommand failed.

I have tried some ways,but it didn't solve the problem

  1. pipenv install jsonschema==3.0.2 from this

  2. update python version to 3.8

Compile Environment: centos 8; linux 5.14.7; python 3.6.8; libvirt main


Solution

  • Could you try this method: In file of /usr/local/lib/python3.6/site-packages/rst2html5/init.py modify to:

    try:
        from importlib import metadata
    except ImportError:
        # Running on pre-3.8 Python; use importlib-metadata package
        import importlib_metadata as metadata  # type: ignore
    

    https://gitlab.com/meltano/sdk/-/issues/58