我从 anaconda 环境中打开了一个 jupyter notebook,但内核使用默认版本的 python 而不是此环境中定义的 python(我安装了所有 pthe 包)。
我怎样才能改变它?
(myEnv) okoub@my-mac:~/Desktop$jupyter notebook
[I 13:35:46.644 NotebookApp] The port 8888 is already in use, trying another port.
[I 13:35:46.646 NotebookApp] The port 8889 is already in use, trying another port.
[I 13:35:46.675 NotebookApp] JupyterLab alpha preview extension loaded from /Users/okoub/anaconda3/lib/python3.6/site-packages/jupyterlab
我正在使用 MAC。
在环境中安装jupyter后:
source activate myEnv
conda install jupyter
jupyter notebook
我得到错误:
File "/Users/okoub/anaconda3/envs/myEnv/lib/python3.5/site-packages/prompt_toolkit/completion/base.py", line 4, in <module>
from prompt_toolkit.eventloop import generator_to_async_generator, AsyncGeneratorItem
ImportError: cannot import name 'generator_to_async_generator'
[W 14:54:56.587 NotebookApp] KernelRestarter: restart failed
[W 14:54:56.587 NotebookApp] Kernel dcc36e3e-9352-402f-a513-ca1dca30e460 died, removing from map.
[W 14:55:41.612 NotebookApp] Timeout waiting for kernel_info reply from dcc36e3e-9352-402f-a513-ca1dca30e460
[E 14:55:41.616 NotebookApp] Error opening stream: HTTP 404: Not Found (Kernel does not exist: dcc36e3e-9352-402f-a513-ca1dca30e460)
[I 14:56:41.524 NotebookApp] Saving file at /my_notebook.ipynb
最佳答案
运行 conda install nb_conda_kernels
,然后重新启动 jupyter
。现在右上角应该有一个额外的选项来选择笔记本应该使用哪个 conda env
来执行代码。这是 IMO 最方便的解决方案,因为您可以在同一个项目中拥有多个笔记本,这些笔记本在各自的环境中运行,而不必一直source activate
。
在这里阅读更多:https://github.com/Anaconda-Platform/nb_conda_kernels
关于python - 将我的 jupyter notebook 设置为使用 python 版本的环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53082441/