Set my jupyter notebook to use python version of an enviroment

只谈情不闲聊 提交于 2020-07-18 06:24:09

问题


I opened a jupyter notebook from an anaconda enviiroment but the kernel uses a default version of python instead of the python defined in this enviroment (That has all pthe packages i installed).

How can I change it?

(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

I am using MAC.

After installing jupyter in the enviroment:

source activate myEnv
conda install jupyter
jupyter notebook

I get the error:

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

回答1:


Run a conda install nb_conda_kernels, then restart jupyter. There should now be an additional option in the top right corner to choose which conda env the notebook should use for code execution. This is the most convenient solution IMO since you can have multiple notebooks in the same project that operate with their own respective environments rather than having to source activate all the time.

Read more here: https://github.com/Anaconda-Platform/nb_conda_kernels




回答2:


You are using jupyter installed in the main anaconda installation path (/Users/okoub/anaconda3/lib/python3.6/site-packages/jupyterlab). If you want to use jupyter with your environment, install it in the desired env.

source activate myEnv
conda install jupyter
jupyter notebook

If you already installed jupyter in your environment, don't forget to activate it before running jupyter notebook.

Sorry I do not know if the way to activate a conda environment is the same on MAC as Linux

following OP's edit:

It looks like you're having an error in prompt_toolkit. Can you try to reinstall it with conda?



来源:https://stackoverflow.com/questions/53082441/set-my-jupyter-notebook-to-use-python-version-of-an-enviroment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!