Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set my jupyter notebook to use python version of an enviroment

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
like image 287
okuoub Avatar asked Oct 31 '18 11:10

okuoub


People also ask

How do I make a Jupyter Notebook use a specific version of Python?

To change the kernel version in Jupyter Python Notebooks follow the steps below : Open the Python Notebook and click on " Kernel " from the menu bar located on top of the python notebook. Click on " Change kernel " from the drop down box that appears and chose the version that is required.

How do I change the Python environment in Jupyter Notebook?

With a new Jupyter notebook open, you can click Kernel > Change kernel > and select the virtual environment you need.

How do I set Python version in environment?

By default, that will be the version of python that is used for any new environment you create. However, you can specify any version of python installed on your computer to use inside a new environment with the -p flag : $ virtualenv -p python3. 2 my_env Running virtualenv with interpreter /usr/local/bin/python3.


1 Answers

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

like image 79
Dascienz Avatar answered Oct 05 '22 12:10

Dascienz