15

I have python versions 3.6.5_1 and 3.7.0installed via Homebrew.
jupyter needs python3.6 for launching. It wouldn't start if I switch to python3.7.

After launching, it fails to start the kernel. Giving this error:

Traceback (most recent call last):
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/vendor/lib/python3.6/site-packages/tornado/web.py", line 1543, in _execute
result = yield result
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/vendor/lib/python3.6/site-packages/tornado/gen.py", line 1099, in run
value = future.result()
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/vendor/lib/python3.6/site-packages/tornado/gen.py", line 1107, in run
yielded = self.gen.throw(*exc_info)
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/lib/python3.6/site-packages/notebook/services/sessions/handlers.py", line 73, in post
type=mtype))
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/vendor/lib/python3.6/site-packages/tornado/gen.py", line 1099, in run
value = future.result()
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/vendor/lib/python3.6/site-packages/tornado/gen.py", line 1107, in run
yielded = self.gen.throw(*exc_info)
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/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 "/usr/local/Cellar/jupyter/1.0.0_4/libexec/vendor/lib/python3.6/site-packages/tornado/gen.py", line 1099, in run
value = future.result()
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/vendor/lib/python3.6/site-packages/tornado/gen.py", line 1107, in run
yielded = self.gen.throw(*exc_info)
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/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 "/usr/local/Cellar/jupyter/1.0.0_4/libexec/vendor/lib/python3.6/site-packages/tornado/gen.py", line 1099, in run
value = future.result()
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/vendor/lib/python3.6/site-packages/tornado/gen.py", line 315, in wrapper
yielded = next(result)
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/lib/python3.6/site-packages/notebook/services/kernels/kernelmanager.py", line 148, in start_kernel
super(MappingKernelManager, self).start_kernel(**kwargs)
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/lib/python3.6/site-packages/jupyter_client/multikernelmanager.py", line 110, in start_kernel
km.start_kernel(**kwargs)
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/lib/python3.6/site-packages/jupyter_client/manager.py", line 259, in start_kernel
**kw)
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/lib/python3.6/site-packages/jupyter_client/manager.py", line 204, in _launch_kernel
return launch_kernel(kernel_cmd, **kw)
File "/usr/local/Cellar/jupyter/1.0.0_4/libexec/lib/python3.6/site-packages/jupyter_client/launcher.py", line 128, in launch_kernel
proc = Popen(cmd, **kwargs)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/opt/python/bin/python3.7': '/usr/local/opt/python/bin/python3.7'

From what I understand, the kernel is looking for python3.7. My kernel list has just python3

$jupyter kernelspec list  
Available kernels:  
python3    /usr/local/etc/jupyter/kernels/python3  

I looked at this link on github, but it wasn't helpful. How do I make jupyter and the kernel running on the same python version?

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
nac001
  • 693
  • 2
  • 9
  • 18
  • to install a kernel on jupyter `python3.7 -m ipykernel install`. Are you sure that all your python3 are install with homebrew ? – Erwan Aug 20 '18 at 16:08
  • @Erwan, yes all my python3 is installed via Homebrew – nac001 Aug 20 '18 at 16:10
  • 1
    Check is jupyter installed for python 3.7 via `help("modules")` in python 3.7 console – Alex Aug 20 '18 at 16:24
  • @Alex, I do not see jupyter in the list of modules. – nac001 Aug 20 '18 at 17:48
  • 1
    @nac001 Use `pip3 install jupyter` to install it. (You need to use `pip` of python 3.7) – Alex Aug 20 '18 at 18:29
  • Please do not edit solution announcements into the question. Accept (i.e. click the "tick" next to it) one of the existing answer, if there are any. You can also create your own answer, and even accept it, if your solution is not yet covered by an existing answer. – Yunnosch Jul 05 '21 at 18:05

5 Answers5

26

Check the kernel specifications:

$jupyter kernelspec list

This will show you the available kernels. In this case:

python3    /usr/local/etc/jupyter/kernels/python3  

Open the kernel.json file in this directory and specify the path of python you want the kernel to use in the argv key.

nac001
  • 693
  • 2
  • 9
  • 18
  • 3
    I am facing the same error , I have run the following command you mentioned in the question and that return me `python3 C:\Users\AHMED\anaconda3\envs\iris_1\share\jupyter\kernels\python3` . Now next i am not understand how can i specify the path of python.. – Ahmed Yasin Nov 10 '20 at 20:48
  • @AhmedYasin, there's a `kernel.json` file in the path you mentioned. You have to change the kernel path there. – nac001 Nov 11 '20 at 18:20
  • 2
    Thanks for this. My `kernel.json` had a path to the python executable in an env, and not the system wide one. This solved it. – Colin Feb 11 '21 at 00:55
  • I ran "which python3" and updated argv with the same path and that fixed my issue. Thank you ! – yogidilip Sep 07 '22 at 21:35
10

Updating the jupyter notebook resolved the issue for me. But remember, update it using command line. Not Anaconda Navigator

pip install -U jupyter
shivampip
  • 2,004
  • 19
  • 19
2

In case anyone anyone reading this who runs Jupyter Notebook from within Anaconda and gets the same error:

I found a workaround by installing Jupyter using pip in the command prompt (not anaconda prompt):

$pip install jupyter

and then start Jupyter using the known way

$cd 'DirectoryofyourNotebook'
$jupyter notebook
Patrick Glettig
  • 541
  • 1
  • 6
  • 12
1

step 2 command:

conda activate <location of your env folder>

step 3 command:

python -m ipykernel install --user

works!

Vishwa Mittar
  • 378
  • 5
  • 16
  • 2
    Please provide a full process as it doesn't include step 1. An explanation as to how this works will further help the OP as well. – David Lee Jul 05 '21 at 20:55
  • 1
    I am sorry for the inconvenience.. step 1 would be starting the terminal... Actually I found this solution from "https://discourse.jupyter.org/t/kernel-error-in-jupyter-notebook-fail-to-start/2260/5" by Claudio_pena and thought it would be helpful for others..Thanks – モブ Mobu Jul 07 '21 at 04:07
0

I had same issue - tried all the above without success.

Context: using Windows on that machine, for a few years. I have used this machine as a "code on the go when I need to" laptop and have not been very careful nor consistent when installing/upgrading python versions or libraries or environments.

The fix for me - somehow a folder that contained f2py.exe (Numpy - on top of which Pandas is built) was not in the path and was in a hidden folder that ended with "\Scripts". Python itself was fine in the environment variables. They were in very different folders - while normally they should be in close branches in the folder tree. Adding the full path of the folder ending with "\Scripts" that have f2py.exe in the environment variables solved the kernel issue for me.

Alexandre Jean
  • 622
  • 2
  • 11
  • 19
  • I assume readers are comfortable with path and env variables. If not check the official doc or the link here https://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows-so-it-finds-my-modules-packages – Alexandre Jean Mar 23 '21 at 10:13