anaconda / nb_conda_kernels

Package for managing conda environment-based kernels inside of Jupyter
BSD 3-Clause "New" or "Revised" License
588 stars 70 forks source link

kernel error in jupyter notebook #55

Closed kdeleeuw11 closed 7 years ago

kdeleeuw11 commented 7 years ago

I have anaconda installed and I am using the jupyter notebook. I just read in the Jupyter Notebook Tutorial from DataCamp (https://www.datacamp.com/community/tutorials/tutorial-jupyter-notebook#gs.4qhxKRs) that when you launch Jupyter Notebook, it should show Python 3 as kernel and not python [conda root] and python [default]. This happened in my environment. To fix this, the tutorial suggests to run 'conda remove _nb_ext_conf'. I have done this on my MacBook where it works fine. I then did the same on my iMac and when launching the Jupyter Notebook, I get 'Kernel Error'. When I click on this, I get the log of which the last line reads as: FileNotFoundError: [Errno 2] No such file or directory: '/Users/kees/anaconda/envs/pyk3/bin/python'.

I had an environment pyk3 in the past, but I re-installed Anaconda with Python 3 as default and I have now an environment py27. Before I did the 'conda remove _nb_ext_conf' the notebook launched ok.

So somewhere there is this link to my old environment. I have been searching but cannot find it.

damianavila commented 7 years ago

Hi, can you run jupyter kernelspec list, that should give you a list of the kernelspecs you have installed...

kdeleeuw11 commented 7 years ago

The result of running jupyter kernelspec list is:

Available kernels: python3 /Users/kees/Library/Jupyter/kernels/python3 ir /Users/kees/anaconda/share/jupyter/kernels/ir octave_kernel /usr/local/share/jupyter/kernels/octave_kernel

When I open a new notebook, I can select any of those 3, but I get the kernel error for all three with the error message: FileNotFoundError: [Errno 2] No such file or directory: '/Users/kees/anaconda/envs/pyk3/bin/python'.

The strange thing is that I don't have an environment pyk3 anymore. When I run source activate pyk3

I get: CondaEnvironmentNotFoundError: Could not find environment: pyk3 . You can list all discoverable environments with conda info --envs.

When I activate my new python environment py27 and then run jupyter kernelspec list, I get:

Available kernels: python2 /Users/kees/anaconda/envs/py27/lib/python2.7/site-packages/ipykernel/resources python3 /Users/kees/Library/Jupyter/kernels/python3 octave_kernel /usr/local/share/jupyter/kernels/octave_kernel

I just found that when I launch jupyter in this py27 environment and when I open a new notebook, I get as possible kernels to choose from: Octave Python 3 Python [conda env:py27] Python [conda root] Python [default]

When I choose e.g. Python [default], I have a working notebook in Python 2, but when I choose Python 3, I get the same error again

damianavila commented 7 years ago

My best guess is about some issue with the previously installed kernels...

Can you back up all your kernels at /Users/kees/Library/Jupyter/kernels/ at some other place and then delete them from that path? And check if things work... thanks!

kdeleeuw11 commented 7 years ago

Yes, great, it now works. Can I leave it like this or should I re-install something?

kdeleeuw11 commented 7 years ago

There was only one folder in /Users/kees/library/Jupyter/kernels/ which is Python3 with the file kernel.json

The content of the kernel.json file is as follows: { "language": "python", "display_name": "Python 3", "argv": [ "/Users/kees/anaconda/envs/pyk3/bin/python", "-m", "ipykernel", "-f", "{connection_file}" ] }

This has indeed the link to the old environment pyk3.

The content of the kernel.json file on my MacBook is: { "argv": ["python3", "-m", "ipykernel", "-f", "{connection_file}"], "display_name": "Python 3", "language": "python3" }

I copied this file over to my /Users/kees/library/Jupyter/kernels/Python3 folder on the Mac. Everything is working fine now.

Thanks very much for your help. Have a good Xmas and a great 2017.

damianavila commented 7 years ago

Everything is working fine now.

Nice!

Thanks very much for your help. Have a good Xmas and a great 2017.

You too!!!

AschHarwood commented 7 years ago

I think I am having a similar problem to this. I deleted and reinstalled my anaconda distribution because of the problem I described here: [https://stackoverflow.com/questions/43681919/import-returning-modulenotfounderror-error-in-jupyter-notebook]. ( I assume this is a result of python 2.7 and 3.6 fighting with each other. I reinstalled because I really dont need python 2.7)

However, when I run Jupyter Notebooks now in I'm getting a "kernel error":

Traceback (most recent call last):
  File "/anaconda/lib/python3.6/site-packages/notebook/base/handlers.py", line 503, in wrapper
    result = yield gen.maybe_future(method(self, *args, **kwargs))
  File "/anaconda/lib/python3.6/site-packages/tornado/gen.py", line 1015, in run
    value = future.result()
  File "/anaconda/lib/python3.6/site-packages/tornado/concurrent.py", line 237, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 3, in raise_exc_info
  File "/anaconda/lib/python3.6/site-packages/tornado/gen.py", line 1021, in run
    yielded = self.gen.throw(*exc_info)
  File "/anaconda/lib/python3.6/site-packages/notebook/services/sessions/handlers.py", line 75, in post
    type=mtype))
  File "/anaconda/lib/python3.6/site-packages/tornado/gen.py", line 1015, in run
    value = future.result()
  File "/anaconda/lib/python3.6/site-packages/tornado/concurrent.py", line 237, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 3, in raise_exc_info
  File "/anaconda/lib/python3.6/site-packages/tornado/gen.py", line 1021, in run
    yielded = self.gen.throw(*exc_info)
  File "/anaconda/lib/python3.6/site-packages/notebook/services/sessions/sessionmanager.py", line 79, in create_session
    kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name)
  File "/anaconda/lib/python3.6/site-packages/tornado/gen.py", line 1015, in run
    value = future.result()
  File "/anaconda/lib/python3.6/site-packages/tornado/concurrent.py", line 237, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 3, in raise_exc_info
  File "/anaconda/lib/python3.6/site-packages/tornado/gen.py", line 1021, in run
    yielded = self.gen.throw(*exc_info)
  File "/anaconda/lib/python3.6/site-packages/notebook/services/sessions/sessionmanager.py", line 92, in start_kernel_for_session
    self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
  File "/anaconda/lib/python3.6/site-packages/tornado/gen.py", line 1015, in run
    value = future.result()
  File "/anaconda/lib/python3.6/site-packages/tornado/concurrent.py", line 237, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 3, in raise_exc_info
  File "/anaconda/lib/python3.6/site-packages/tornado/gen.py", line 285, in wrapper
    yielded = next(result)
  File "/anaconda/lib/python3.6/site-packages/notebook/services/kernels/kernelmanager.py", line 87, in start_kernel
    super(MappingKernelManager, self).start_kernel(**kwargs)
  File "/anaconda/lib/python3.6/site-packages/jupyter_client/multikernelmanager.py", line 110, in start_kernel
    km.start_kernel(**kwargs)
  File "/anaconda/lib/python3.6/site-packages/jupyter_client/manager.py", line 243, in start_kernel
    **kw)
  File "/anaconda/lib/python3.6/site-packages/jupyter_client/manager.py", line 189, in _launch_kernel
    return launch_kernel(kernel_cmd, **kw)
  File "/anaconda/lib/python3.6/site-packages/jupyter_client/launcher.py", line 123, in launch_kernel
    proc = Popen(cmd, **kwargs)
  File "/anaconda/lib/python3.6/subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "/anaconda/lib/python3.6/subprocess.py", line 1326, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/aschharwood/anaconda/envs/ipykernel_py2/bin/python'

This missing directory is leftover from before my Anaconda reinstall.

As requested above, I did run jupyter kernelspec list and here is what it returned:

Aschs-MacBook-Air:new_dict aschharwood$ jupyter kernelspec list Available kernels: python3 /Users/aschharwood/Library/Jupyter/kernels/python3 Aschs-MacBook-Air:new_dict aschharwood$

Any ideas what I need to do?

damianavila commented 7 years ago

This missing directory is leftover from before my Anaconda reinstall.

Maybe some kernelspec hidden somewhere trying to load that kernel?

qweszxc7410 commented 6 years ago

My path as follows: C:\Users\User\AppData\Roaming\jupyter\kernels\python3\kernel.json C:\ProgramData\jupyter\kernels\python3\kernel.jsopn

After I changed path, "Kernel Error" is not display

{ "argv": [ "C:\Python35\python.exe", "-m", "ipykernel_launcher", "-f", "{connection_file}" ], "display_name": "Python 3", "language": "python" }

denson commented 5 years ago

When doing a fresh install you need to delete the Jupyter library directory to clear leftovers:

/Users/<yourusername>/library/Jupyter/
rkogeyama commented 4 years ago

I have a similar problem but I cannot locate the folder to be cleared. I am running conda 4.5.11 in a shared server running CentOS Linux 7 (Core). I can't find a ~/library folder, or a /User/kees. Any ideas?