We’ve all been there. You go to accomplish what seems like a small change, tweak or update to a computer program and everything goes bananas. In my case, I was downloading the package handson-ml2, the companion to the excellent machine learning textbook.
The terminal code was supposed to have me create a virtual environment and then activate the package inside that environment but clearly I did not follow those instructions correctly.
Whatever the case, I was left with a Jupyter Notebook that could not start a Python kernel. Yikes! After about 90 minutes I was back, so here are some directions if you find yourself in this situation.
- At the Anaconda Prompt, type “where python” (without quotes) to find your Python.exe file
- Type “jupyter kernelspec list” (no quotes) to find your list of kernels
- Find the one that starts with Python 3 and navigate to that path, it likely looks like this: python3 C:\Users\Dustin\AppData\Roaming\jupyter\kernels\python3
- Open up the kernel.json file in a text editor and fix the path so that it looks like the one from where python above – make sure you use \\ instead of \ ones (so C:\Dustin would actually be C:\\Dustin)
- Reopen your Anaconda Prompt as Administrator and run conda update conda and conda update jupyter-notebook (saying yes to update each time)
- Open Jupyter Notebook and navigate to the Environment tab
- Click Update Index
And you’re done!
Long Version (with extra steps)
This long version is the actual set of steps I took. The short version removed a couple of steps that I feel were troubleshooting only and didn’t help. It also adds a lot more detail as to what each of the commands do.
1. Open Anaconda Prompt
2. Type “where python” (no quotes) That will tell you where your Python.exe is, it should be in C:\Users\YourName\anaconda3\python.exe, something like that.
Note that the AppData/Local version of Python is NOT the one I want. That’s a temporary one. The one I really want is the one in the Anaconda file.
3. Type “jupyter kernelspec list” (again no quotes)
In my case, I have only one kernel on my system. If you had multiple kernels, they would be listed here. Find the one that isn’t broken. (If you’re not sure, you likely only have the one like me.)
4. Go to the file path indicated, and open up kernel.json in a text editor
5. Make sure the path listed for argv is the same one that where python told you. Use double back slashes.
Then save. In my case, the package installation and environment creation I had attempted to do previously changed my environment so Jupyter Notebook couldn’t find the kernel at all. That’s what it was failing.
6. After updating the path, I uninstalled Anaconda, then I deleted the 3GB of junk it left in the anaconda3 folders there (what did the uninstaller do if not delete that?) I don’t think steps 6 or 7 are really necessary but I was troubleshooting.
7. Then I reinstalled Anaconda Navigator.
8. After reinstalling Anaconda, I re-opened Anaconda Prompt but this time as admin. I ran conda update conda and conda update anaconda-navigator (saying yes to update each time)
9. After updating conda and Anaconda Navigator, I reopened Anaconda Navigator, clicked the Environment tab, clicked Update Index.
Now when I reopen Anaconda Navigator it detects that I have Jupyter Notebook installed. When I reopen Jupyter, the kernel doesn’t die. Hope this helps if your kernel dies from a botched package in the future
Hope this helps!