为什么Jupyter笔记本无法打开内核?

时间:2019-05-25 16:51:08

标签: python-3.x jupyter-notebook jupyter

我最近在新计算机上安装了Jupyter,在尝试使用virtualenv和不使用python -m notebook之后,我收到以下与线程模块相关的错误。此错误会阻止笔记本计算机(1)打开或(2)启动内核。

打开Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 183, in _run_module_as_main mod_name, mod_spec, code = _get_module_details(mod_name, _Error) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 142, in _get_module_details return _get_module_details(pkg_main_name, error) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 109, in _get_module_details __import__(pkg_name) File "/Users/me/Documents/Code/Python/Environments/Jupyter/lib/python3.7/site-packages/notebook/__init__.py", line 25, in <module> from .nbextensions import install_nbextension File "/Users/me/Documents/Code/Python/Environments/Jupyter/lib/python3.7/site-packages/notebook/nbextensions.py", line 31, in <module> from .config_manager import BaseJSONConfigManager File "/Users/me/Documents/Code/Python/Environments/Jupyter/lib/python3.7/site-packages/notebook/config_manager.py", line 15, in <module> from traitlets.config import LoggingConfigurable File "/Users/me/Documents/Code/Python/Environments/Jupyter/lib/python3.7/site-packages/traitlets/config/__init__.py", line 6, in <module> from .application import * File "/Users/me/Documents/Code/Python/Environments/Jupyter/lib/python3.7/site-packages/traitlets/config/application.py", line 11, in <module> import logging File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/__init__.py", line 210, in <module> _lock = threading.RLock() AttributeError: module 'threading' has no attribute 'RLock' Exception ignored in: <module 'threading' from '/Users/me/Downloads/threading.py'> AttributeError: module 'threading' has no attribute '_shutdown' 时出错。笔记本无法成功打开。

notebook

切换目录,成功打开[I 09:32:05.828 NotebookApp] KernelRestarter: restarting kernel (3/5), new random ports Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code exec(code, run_globals) File "/Users/me/Documents/Code/Python/Environments/Jupyter/lib/python3.7/site-packages/ipykernel_launcher.py", line 15, in <module> from ipykernel import kernelapp as app File "/Users/me/Documents/Code/Python/Environments/Jupyter/lib/python3.7/site-packages/ipykernel/__init__.py", line 2, in <module> from .connect import * File "/Users/me/Documents/Code/Python/Environments/Jupyter/lib/python3.7/site-packages/ipykernel/connect.py", line 13, in <module> from IPython.core.profiledir import ProfileDir File "/Users/me/Documents/Code/Python/Environments/Jupyter/lib/python3.7/site-packages/IPython/__init__.py", line 54, in <module> from .core.application import Application File "/Users/me/Documents/Code/Python/Environments/Jupyter/lib/python3.7/site-packages/IPython/core/application.py", line 18, in <module> import logging File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/__init__.py", line 210, in <module> _lock = threading.RLock() AttributeError: module 'threading' has no attribute 'RLock' Exception ignored in: <module 'threading' from '/Users/me/Downloads/threading.py'> AttributeError: module 'threading' has no attribute '_shutdown' 并尝试连接到内核后出现错误

site-packages

由于线程是内置模块,因此我无法对其进行更新。同样,使用常规virtualenv安装和干净的threading.py安装,此结果是相同的。

1 个答案:

答案 0 :(得分:0)

我发现此错误是由于我的主目录的子目录中存在一个名为threading(与内置模块无关)的文件引起的。如果我从当前目录下目录树中文件所在位置的任何目录启动笔记本,则会收到此错误。

解决方案是在与内置import threading不存在命名冲突的目录中启动笔记本。

奇怪的是,如果我在发生故障的相同目录中的Python shell中dir(threading),并运行n x n,它将获取正确的软件包。为什么Jupyter对此有不同的对待?