将我的jupyter笔记本设置为使用python版本的enviromen

2024-09-30 16:34:18 发布

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

我从一个anaconda环境打开了一个jupyter笔记本,但是内核使用的是默认版本的python,而不是在这个环境中定义的python(它包含我安装的所有包)。在

我怎样才能改变它?在

(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后:

^{pr2}$

我得到了一个错误:

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

Tags: theinfrom环境portmyjupytergenerator
2条回答

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

source activate myEnv
conda install jupyter
jupyter notebook

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

抱歉,我不知道激活conda环境的方式是否与Linux相同

以下操作编辑:

看起来您在prompt_toolkit中出错。你能试着用康达重新安装吗?在

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

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

相关问题 更多 >