首页 > 解决方案 > Anaconda Jupyter Notebook Kernel error ImportError: DLL load failed while importing win32api: The specified procedure could not be found

问题描述

我之前在 Visual Studio 代码中运行过 python 3.8 和 jupyter notebook。安装 Anaconda 后,我无法再运行 jupyter notebook,并且出现内核错误。

Traceback (most recent call last):
  File "C:\Users\*****\AppData\Roaming\Python\Python38\site-packages\tornado\web.py", line 1704, in _execute
    result = await result
  File "C:\Users\*****\AppData\Roaming\Python\Python38\site-packages\tornado\gen.py", line 769, in run
yielded = self.gen.throw(*exc_info)  # type: ignore
  File "C:\ProgramData\Anaconda3\lib\site-packages\notebook\services\sessions\handlers.py", line 69, in post
model = yield maybe_future(
  File "C:\Users\*****\AppData\Roaming\Python\Python38\site-packages\tornado\gen.py", line 762, in run
value = future.result()
  File "C:\Users\*****\AppData\Roaming\Python\Python38\site-packages\tornado\gen.py", line 769, in run
yielded = self.gen.throw(*exc_info)  # type: ignore
  File "C:\ProgramData\Anaconda3\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 98, in create_session
kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name)
  File "C:\Users\*****\AppData\Roaming\Python\Python38\site-packages\tornado\gen.py", line 762, in run
value = future.result()
  File "C:\Users\*****\AppData\Roaming\Python\Python38\site-packages\tornado\gen.py", line 769, in run
yielded = self.gen.throw(*exc_info)  # type: ignore
  File "C:\ProgramData\Anaconda3\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 110, in start_kernel_for_session
kernel_id = yield maybe_future(
  File "C:\Users\*****\AppData\Roaming\Python\Python38\site-packages\tornado\gen.py", line 762, in run
value = future.result()
  File "C:\ProgramData\Anaconda3\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 176, in start_kernel
kernel_id = await maybe_future(self.pinned_superclass.start_kernel(self, **kwargs))
  File "C:\Users\*****\AppData\Roaming\Python\Python38\site-packages\jupyter_client\multikernelmanager.py", line 186, in start_kernel
km.start_kernel(**kwargs)
  File "C:\Users\*****\AppData\Roaming\Python\Python38\site-packages\jupyter_client\manager.py", line 337, in start_kernel
kernel_cmd, kw = self.pre_start_kernel(**kw)
  File "C:\Users\*****\AppData\Roaming\Python\Python38\site-packages\jupyter_client\manager.py", line 286, in pre_start_kernel
self.write_connection_file()
  File "C:\Users\*****\AppData\Roaming\Python\Python38\site-packages\jupyter_client\connect.py", line 466, in write_connection_file
self.connection_file, cfg = write_connection_file(self.connection_file,
  File "C:\Users\*****\AppData\Roaming\Python\Python38\site-packages\jupyter_client\connect.py", line 136, in write_connection_file
with secure_write(fname) as f:
  File "C:\ProgramData\Anaconda3\lib\contextlib.py", line 113, in __enter__
return next(self.gen)
  File "C:\Users\*****\AppData\Roaming\Python\Python38\site-packages\jupyter_core\paths.py", line 461, in secure_write
win32_restrict_file_to_user(fname)
  File "C:\Users\*****\AppData\Roaming\Python\Python38\site-packages\jupyter_core\paths.py", line 387, in win32_restrict_file_to_user
import win32api
ImportError: DLL load failed while importing win32api: The specified procedure could not be found.

我已经尝试过conda install ipykernel --update-depsconda install pywin32但问题仍然存在。我怎样才能解决这个问题?

标签: pythonjupyter-notebookanaconda

解决方案


这个建议对我有用: pip uninstall pywin32 然后 conda 再次安装它: https://github.com/jupyter/notebook/issues/4980#issuecomment-663885620

如何使用 conda 中的 pip:打开 Anaconda。在主页下方的左侧窗格中选择环境。在您选择的位置右侧和“搜索环境”栏下方,您应该看到 base(root)。点击它。应该出现一个指向右侧的三角形,单击它并选择“打开终端”在此处使用常规 pip install 命令。

然后如何使用 anaconda 安装 pywin32:根据本网站https://anaconda.org/anaconda/pywin32以管理员身份从 anaconda 提示符运行 conda install :

conda install -c anaconda pywin32


推荐阅读