'Kernel Error in Jupyter Notebook on Anaconda 2019.03 for Python 3.7 on macOS

I just installed Anaconda 2019.03 for macOS with Python 3.7 and would like to use it for Python 3 programming with Jupyter Notebook. When I run Jupyter Notebook nothing works because of a Kernel error.

I had uninstalled Anaconda for Python 2.7 and Python 3.7 before reinstalling it (I uninstalled and reinstalled because of a separate problem), and I think that some important kernel files may have been deleted when I manually uninstalled Anaconda. I think the error message below shows that Anaconda is launching from a folder called anaconda3 inside of root (/) but in the last line of the error message, it seems to be looking for something in my home folder (myhomefolder). I'm not really sure how to interpret this since I'm fairly new to this.

Traceback (most recent call last):
  File "/anaconda3/lib/python3.7/site-packages/tornado/web.py", line 1699, in _execute
    result = await result
  File "/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 736, in run
    yielded = self.gen.throw(*exc_info)  # type: ignore
  File "/anaconda3/lib/python3.7/site-packages/notebook/services/sessions/handlers.py", line 73, in post
    type=mtype))
  File "/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 729, in run
    value = future.result()
  File "/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 736, in run
    yielded = self.gen.throw(*exc_info)  # type: ignore
  File "/anaconda3/lib/python3.7/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 "/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 729, in run
    value = future.result()
  File "/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 736, in run
    yielded = self.gen.throw(*exc_info)  # type: ignore
  File "/anaconda3/lib/python3.7/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 "/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 729, in run
    value = future.result()
  File "/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 209, in wrapper
    yielded = next(result)
  File "/anaconda3/lib/python3.7/site-packages/notebook/services/kernels/kernelmanager.py", line 160, in start_kernel
    super(MappingKernelManager, self).start_kernel(**kwargs)
  File "/anaconda3/lib/python3.7/site-packages/jupyter_client/multikernelmanager.py", line 110, in start_kernel
    km.start_kernel(**kwargs)
  File "/anaconda3/lib/python3.7/site-packages/jupyter_client/manager.py", line 259, in start_kernel
    **kw)
  File "/anaconda3/lib/python3.7/site-packages/jupyter_client/manager.py", line 204, in _launch_kernel
    return launch_kernel(kernel_cmd, **kw)
  File "/anaconda3/lib/python3.7/site-packages/jupyter_client/launcher.py", line 138, in launch_kernel
    proc = Popen(cmd, **kwargs)
  File "/anaconda3/lib/python3.7/subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "/anaconda3/lib/python3.7/subprocess.py", line 1522, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/myhomefolder/anaconda/envs/ipykernel_py3/bin/python': '/Users/myhomefolder/anaconda/envs/ipykernel_py3/bin/python'


Solution 1:[1]

The solution was to run the following command in the terminal:

python -m ipykernel install --user,

which, I believe installs the kernel. I found the solution on the following GitHub post, launching jupyter i get kernel error #2301.

I don't know if this is the most complete solution that will avoid similar problems in the future, but it seems to work for now. If anyone has other suggestions, I'm happy to hear about them, of course.

Solution 2:[2]

I have tried the following and it did work for me (after trying multiple solution on Stackoverflow).

Install ipykernel

conda install ipykernel
python -m ipykernel install --user

Apply the ipykernel to your current venv

ipython kernel install --name your_env_name --user

Uninstall the pywin32 dep and reinstall it:

pip uninstall pywin32
conda install pywin32

Upgrade Conda to the latest version (this sometimes fix some installation problems)

conda update -n base -c defaults conda

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Data2Dollars
Solution 2 Mohamed Ismaiel Ahmed