Jupiter notebook run error: AttributeError: module 'importlib_metadata' has no attribute 'version'

Viewed 8351

Originally, Jupyter notebook was running well without any problems. But after installing tensorflow and keras today, it doesn't work.

Error message:

Traceback (most recent call last):
  File "C:\Anaconda3\Scripts\jupyter-notebook-script.py", line 6, in <module>
    from notebook.notebookapp import main
  File "C:\Anaconda3\lib\site-packages\notebook\notebookapp.py", line 85, in <module>
    from .services.contents.manager import ContentsManager
  File "C:\Anaconda3\lib\site-packages\notebook\services\contents\manager.py", line 17, in <module>
    from nbformat import sign, validate as validate_nb, ValidationError
  File "C:\Anaconda3\lib\site-packages\nbformat\__init__.py", line 32, in <module>
    from .validator import validate, ValidationError
  File "C:\Anaconda3\lib\site-packages\nbformat\validator.py", line 12, in <module>
    from .json_compat import get_current_validator, ValidationError
  File "C:\Anaconda3\lib\site-packages\nbformat\json_compat.py", line 10, in <module>
    import jsonschema
  File "C:\Anaconda3\lib\site-packages\jsonschema\__init__.py", line 34, in <module>
    __version__ = metadata.version("jsonschema")
AttributeError: module 'importlib_metadata' has no attribute 'version'
3 Answers

There is a problem with your importlib_metadata package, you can try uninstall it first and then forcing out a new installation with the following commands:

pip uninstall importlib_metadata 
pip install importlib_metadata --force-reinstall

It worked for me.

For me, the same error happened after VSCode proposed me to install a tensorboard plugin and I pressed yes. (MacOS 11.4, Conda 4.10.3)

It appears that it introduced some kind of version mismatch for multiple packages in the environment.

The following fixed the problem:

conda update --all

This is a problem with the Anaconda version upgrade. You can solve this with the following command that worked for me.

conda install -c conda-forge importlib_metadata
Related