升级软件包后,Jupyter Notebook无法正常工作

时间:2019-11-29 08:29:47

标签: python jupyter-notebook

我已经创建了一个新的虚拟环境,并通过运行pipenv install jupyter安装了jupyter notebook。我现在无法运行jupyter notebook

Traceback (most recent call last):
  File "c:\users\user\.virtualenvs\jupyter_project-rx9grp37\lib\site-packages\jsonschema\__init__.py", line 31, in <module>
    from importlib import metadata
ImportError: cannot import name 'metadata' from 'importlib' (C:\anaconda\Lib\importlib\__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\anaconda\Lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\anaconda\Lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\user\.virtualenvs\jupyter_project-RX9gRp37\Scripts\jupyter-notebook.EXE\__main__.py", line 4, in <module>
  File "c:\users\user\.virtualenvs\jupyter_project-rx9grp37\lib\site-packages\notebook\notebookapp.py", line 80, in <module>
    from .services.contents.manager import ContentsManager
  File "c:\users\user\.virtualenvs\jupyter_project-rx9grp37\lib\site-packages\notebook\services\contents\manager.py", line 17, in <module>
    from nbformat import sign, validate as validate_nb, ValidationError
  File "c:\users\user\.virtualenvs\jupyter_project-rx9grp37\lib\site-packages\nbformat\__init__.py", line 33, in <module>
    from .validator import validate, ValidationError
  File "c:\users\user\.virtualenvs\jupyter_project-rx9grp37\lib\site-packages\nbformat\validator.py", line 12, in <module>
    from jsonschema import ValidationError
  File "c:\users\user\.virtualenvs\jupyter_project-rx9grp37\lib\site-packages\jsonschema\__init__.py", line 33, in <module>
    import importlib_metadata as metadata
  File "c:\users\user\.virtualenvs\jupyter_project-rx9grp37\lib\site-packages\importlib_metadata\__init__.py", line 547, in <module>
    __version__ = version(__name__)
  File "c:\users\user\.virtualenvs\jupyter_project-rx9grp37\lib\site-packages\importlib_metadata\__init__.py", line 509, in version
    return distribution(distribution_name).version
  File "c:\users\user\.virtualenvs\jupyter_project-rx9grp37\lib\site-packages\importlib_metadata\__init__.py", line 482, in distribution
    return Distribution.from_name(distribution_name)
  File "c:\users\user\.virtualenvs\jupyter_project-rx9grp37\lib\site-packages\importlib_metadata\__init__.py", line 183, in from_name
    dist = next(dists, None)
  File "c:\users\user\.virtualenvs\jupyter_project-rx9grp37\lib\site-packages\importlib_metadata\__init__.py", line 452, in <genexpr>
    return (item for item in root.iterdir()
  File "C:\anaconda\Lib\pathlib.py", line 1090, in iterdir
    for name in self._accessor.listdir(self):
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\user\\Documents\\Python\\jupyter_project\\ '

我正在运行python 3.7。

该问题似乎是由于jsonschema工作方式的最新变化引起的。在3.0.2版中,它似乎可以按预期工作。

发生了什么变化(jsonschema/__init__.py):

之前:

from pkg_resources import get_distribution
__version__ = get_distribution(__name__).version

之后:

try:
    from importlib import metadata
except ImportError: # for Python<3.8
    import importlib_metadata as metadata
__version__ = metadata.version("jsonschema")

除了降级为jsonschema==3.0.2之外,还有其他解决方法吗?

谢谢

2 个答案:

答案 0 :(得分:2)

在虚拟环境中使用python 3.6在这里遇到同样的问题。

答案 1 :(得分:2)

在您的环境中升级您的jsonschema版本

在conda环境中 conda upgrade jsonschema

在点子环境中 pip install --upgrade jsonschema

这对我有用!