Search code examples
jupyter-notebookanacondacondavirtual-environment

Use conda environment in Jupyter Notebook


I am running Anaconda on windows 10 and using Jupyter Notebook for my Machine Learning projects.

I recently became aware of virtual environments in conda.

I created a virtual environment in conda using following command

conda create -n test1

activated the environment

activate test1

installed environment in ipykernel (not sure correct terminology is used)

python -m ipykernel install --user --name test1

now the environment test1 is visible in jupyter notebook but when i start it I am getting kernel starting... please wait message.

here are some snippets.

Environment is showing while creating new file.

Kernel is busy always.

also in jupyter prompt (again not sure about the terms) i am getting following error

[I 21:08:24.924 NotebookApp] Creating new notebook in /MachineLearning/ImageProcessing
[I 21:08:29.550 NotebookApp] Kernel started: ec56795d-df5b-48d5-8f95-473ab1253407
Traceback (most recent call last):
  File "C:\Users\shesh\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\shesh\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\shesh\AppData\Roaming\Python\Python38\site-packages\ipykernel_launcher.py", line 16, in <module>
    app.launch_new_instance()
  File "C:\Users\shesh\AppData\Roaming\Python\Python38\site-packages\traitlets\config\application.py", line 663, in launch_instance
    app.initialize(argv)
  File "<C:\Users\shesh\AppData\Roaming\Python\Python38\site-packages\decorator.py:decorator-gen-125>", line 2, in initialize
  File "C:\Users\shesh\AppData\Roaming\Python\Python38\site-packages\traitlets\config\application.py", line 87, in catch_config_error
    return method(app, *args, **kwargs)
  File "C:\Users\shesh\AppData\Roaming\Python\Python38\site-packages\ipykernel\kernelapp.py", line 527, in initialize
    self.init_sockets()
  File "C:\Users\shesh\AppData\Roaming\Python\Python38\site-packages\ipykernel\kernelapp.py", line 287, in init_sockets
    self.init_iopub(context)
  File "C:\Users\shesh\AppData\Roaming\Python\Python38\site-packages\ipykernel\kernelapp.py", line 295, in init_iopub
    self.iopub_thread = IOPubThread(self.iopub_socket, pipe=True)
  File "C:\Users\shesh\AppData\Roaming\Python\Python38\site-packages\ipykernel\iostream.py", line 68, in __init__
    self._setup_pipe_in()
  File "C:\Users\shesh\AppData\Roaming\Python\Python38\site-packages\ipykernel\iostream.py", line 141, in _setup_pipe_in
    self._pipe_in = ZMQStream(pipe_in, self.io_loop)
  File "C:\Users\shesh\AppData\Roaming\Python\Python38\site-packages\zmq\eventloop\zmqstream.py", line 127, in __init__
    self._init_io_state()
  File "C:\Users\shesh\AppData\Roaming\Python\Python38\site-packages\zmq\eventloop\zmqstream.py", line 546, in _init_io_state
    self.io_loop.add_handler(self.socket, self._handle_events, self.io_loop.READ)
  File "C:\Users\shesh\AppData\Roaming\Python\Python38\site-packages\tornado\platform\asyncio.py", line 99, in add_handler
    self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
  File "C:\Users\shesh\AppData\Local\Programs\Python\Python38\lib\asyncio\events.py", line 501, in add_reader
    raise NotImplementedError
NotImplementedError
[W 21:09:29.591 NotebookApp] Timeout waiting for kernel_info reply from ec56795d-df5b-48d5-8f95-473ab1253407
[I 21:10:29.197 NotebookApp] Saving file at /MachineLearning/ImageProcessing/Untitled.ipynb

All I want to do is use newly created environment in jupyter notebook.


Solution

  • Please try the following steps:

    source activate test1
    conda install ipykernel
    ipython kernel install --name test1 --user