将我的 jupyter notebook 设置为使用 python 版本的环境

oku*_*oub 5 python anaconda jupyter-notebook

我从 anaconda 环境中打开了一个 jupyter 笔记本,但内核使用默认版本的 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
Run Code Online (Sandbox Code Playgroud)

我正在使用MAC。

在环境中安装jupyter后:

source activate myEnv
conda install jupyter
jupyter notebook
Run Code Online (Sandbox Code Playgroud)

我收到错误:

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
Run Code Online (Sandbox Code Playgroud)

Das*_*enz 7

运行 a conda install nb_conda_kernels,然后重新启动jupyter。现在右上角应该有一个额外的选项来选择conda env应该使用哪个笔记本来执行代码。这是 IMO 最方便的解决方案,因为您可以在同一个项目中拥有多个笔记本,它们可以在各自的环境中运行,而不必source activate一直这样。

在此处阅读更多信息:https : //github.com/Anaconda-Platform/nb_conda_kernels


Eri*_* C. 5

您正在使用安装在 anaconda 主安装路径 ( /Users/okoub/anaconda3/lib/python3.6/site-packages/jupyterlab) 中的 jupyter。如果您想在您的环境中使用 jupyter,请将其安装在所需的环境中。

source activate myEnv
conda install jupyter
jupyter notebook
Run Code Online (Sandbox Code Playgroud)

如果您已经在环境中安装了 jupyter,请不要忘记在运行 jupyter Notebook 之前激活它。

抱歉,不知道MAC上激活conda环境的方式和Linux上是否一样

以下OP的编辑:

看来您在 中遇到了错误prompt_toolkit。你可以尝试用 conda 重新安装它吗?