Jupyter笔记本无法连接到Python 3.4虚拟环境上的内核

2024-10-01 07:27:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我用的是运行MacOS10.11.6(ElCapitan)的Mac电脑。我安装了Python版本2.7和3.4作为框架从python.org网站. 最近,我还使用Anaconda安装了python3.6,因为我需要一些无法通过其他方式安装的库。在

多年来,我使用Python 3.4创建了许多虚拟环境,使用:

$ virtualenv -p /Library/Frameworks/Python.framework/Versions/3.4/bin/python3 env34

并使用以下方法激活环境:

^{pr2}$

我安装了许多软件包,包括numpy、pandas和jupyter,使用:

(env34) $ pip install package_name

这一直很有效。在

然而,最近(在中断了大约4个月的Python编码之后),我尝试了同样的方法,但是pip没有工作,我不得不使用get安装最新版本-点对点具体如下:

(env34) $ python get-pip.py

这使我能够将我需要的所有软件包安装到虚拟环境中。所有的安装工作似乎进展顺利。在

但是,当我现在跑步时:

(env34) $ jupyter notebook

…jupyter主页按预期打开,但没有.ipynb文件(新创建或以前保存的文件)可用。在终端窗口中生成了一长串问题列表,最后几行是:

AttributeError: '_UnixSelectorEventLoop' object has no attribute 'is_closed'
[W 21:52:53.476 NotebookApp] Timeout waiting for kernel_info reply from 370a344d-73f3-4d47-899e-0a9250230881
[E 21:52:53.479 NotebookApp] Error opening stream: HTTP 404: Not Found (Kernel does not exist: 370a344d-73f3-4d47-899e-0a9250230881)
[W 21:52:53.986 NotebookApp] KernelRestarter: restart failed
[W 21:52:53.987 NotebookApp] Kernel fa941bc9-f848-4339-bbb3-6dd120a9590e died, removing from map.
[W 21:53:39.000 NotebookApp] Timeout waiting for kernel_info reply from fa941bc9-f848-4339-bbb3-6dd120a9590e
[E 21:53:39.001 NotebookApp] Error opening stream: HTTP 404: Not Found (Kernel does not exist: fa941bc9-f848-4339-bbb3-6dd120a9590e)

这是我做错了什么,是Python干扰还是最近更新的jupyter包引入了一个bug?在

编辑

根据请求,当我第一次启动jupyter notebook时,在~/Library/jupyter/runtime中创建了以下nbserver文件:

{
  "base_url": "/",
  "hostname": "localhost",
  "notebook_dir": "/Users/path_to_virtual_environment",
  "password": false,
  "pid": 5022,
  "port": 8888,
  "secure": false,
  "token": "4cd65924e50aa87bba1d18ce1fa50b1ce50f9faacf0cce95",
  "url": "http://localhost:8888/"
}

当我试图打开ipynb文件时,创建了以下内核文件:

{
  "key": "7c487ae2-3fbe631137bfbf14d419bb53",
  "stdin_port": 60735,
  "control_port": 60736,
  "shell_port": 60733,
  "transport": "tcp",
  "signature_scheme": "hmac-sha256",
  "ip": "127.0.0.1",
  "hb_port": 60737,
  "iopub_port": 60734,
  "kernel_name": ""
}

Tags: pip文件from版本port虚拟环境jupyterkernel