为什么我在 Jupyter Notebook 中出现内核错误?

Why do I have a Kernel Error in Jupyter Notebook?

我是 python 的新手。打开 jupyter notebook 时,我在内核中收到以下错误。有什么想法可以解决吗? jupyter 的安装是通过 Anaconda3 完成的——尝试重新安装和设置环境变量,但到目前为止还没有成功。任何帮助将不胜感激。

 Traceback (most recent call last):
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\tornado\web.py", line 1699, in _execute
        result = await result
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\tornado\gen.py", line 742, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\notebook\services\sessions\handlers.py", line 72, in post
        type=mtype))
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\tornado\gen.py", line 735, in run
        value = future.result()
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\tornado\gen.py", line 742, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\notebook\services\sessions\sessionmanager.py", line 88, in create_session
        kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name)
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\tornado\gen.py", line 735, in run
        value = future.result()
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\tornado\gen.py", line 742, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\notebook\services\sessions\sessionmanager.py", line 101, in start_kernel_for_session
        self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\tornado\gen.py", line 735, in run
        value = future.result()
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\tornado\gen.py", line 209, in wrapper
        yielded = next(result)
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\notebook\services\kernels\kernelmanager.py", line 168, in start_kernel
        super(MappingKernelManager, self).start_kernel(**kwargs)
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\jupyter_client\multikernelmanager.py", line 110, in start_kernel
        km.start_kernel(**kwargs)
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\jupyter_client\manager.py", line 240, in start_kernel
        self.write_connection_file()
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\jupyter_client\connect.py", line 547, in write_connection_file
        kernel_name=self.kernel_name
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\jupyter_client\connect.py", line 212, in write_connection_file
        with secure_write(fname) as f:
      File "C:\Users\drag88\Anaconda3\lib\contextlib.py", line 112, in __enter__
        return next(self.gen)
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\jupyter_client\connect.py", line 100, in secure_write
        win32_restrict_file_to_user(fname)
      File "C:\Users\drag88\AppData\Roaming\Python\Python37\site-packages\jupyter_client\connect.py", line 53, in win32_restrict_file_to_user
        import win32api
    ImportError: DLL load failed: The specified procedure could not be found.

如果您通过 cmd 或 powershell 运行 在您的电脑上安装了 Python:

pip install jupyterlab

然后你可以开始:

jupyter lab

看起来您安装了 jupyter,但它对 Windows 的依赖性存在问题。请参阅 https://github.com/jupyterlab/jupyterlab/issues/7259。我运行陷入同样的​​错误。

它现在应该已在 conda 上修复,因此如果您从 conda 卸载并重新安装 jupyterlab,它应该不会再抛出该错误。

安装可能遗漏了一些已由 post_install 修复的步骤。 转到 yout venv 的脚本目录和 运行 命令

python .\pywin32_postinstall.py -install

确保您运行拥有管理员权限shell。

  • 第 2 步命令:conda activate (location of your env folder)
  • 第 3 步命令:python -m ipykernel install --user

适用于 Windows。

此错误有时是由于之前创建的已删除环境造成的。对于 Windows 用户,运行 在 cmd

中输入以下代码

python -m ipykernel install –user