Missing python kernel in jupyter notebook - python

I am new to jupyter/ipython. I usually start the notebook on a remote machine and create a ssh tunnel. Details of how the tunnel is set up can be found here: http://www.hydro.washington.edu/~jhamman/hydro-logic/blog/2013/10/04/pybook-remote/
However, many times when I start a notebook, it reports back with 0 active kernels (not all the times). Following is the screenshot of that:
-bash-4.1$ jupyter notebook --no-browser --port=7777
[NotebookApp] Serving notebooks from local directory: /x/y/z
[NotebookApp] 0 active kernels
[NotebookApp] The Jupyter Notebook is running at: http://localhost:7777/
[NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
I obviously have python.
python --version
Python 2.7.11 :: Anaconda 2.0.1 (64-bit)
Can someone explain to me this erratic behavior? and how it can be fixed?
Any help would be appreciated.
Thank you
Attached is the error I get:

I also use jupyter using a ssh tunnel and was getting 0 active kernels message and I could not run any notebook. My error snapshot is here. The ipython kernel was not installed properly in the direct install of jupyter using sudo -H pip install jupyter. I resolved it by updating the ipython kernel using:
sudo apt-get -y install ipython ipython-notebook
sudo -H pip install jupyter
If it doesn't work, try uninstalling jupyter and then install packages in sequence as explained in this link.

Related

Cannot open Jupyter Notebook in Ubuntu system

I am trying to open Jupyter Notebook from Ubuntu terminal, but it fails to start because of permission issues. Specifically, a webpage would open up in the Firefox browser, which displays the error message
The file at /home/<user>/.local/share/jupyter/runtime/nbserver-61219-open.html is not readable.
I have found an similar issue at Cannot open new Jupyter Notebook [Permission Denied], which suggests that I should change the ownership of the folder by typing the command
sudo chown -R <user>:<user> ~/.local/share/jupyter
However, this did not work for me. I have also tried other suggestions from https://github.com/microsoft/WSL/issues/3608. The commands sudo jupyter-notebook --allow-root or sudo jupyter notebook --allow-root result in errors saying that the commands are not found. I have also tried chmod -R 777 <my directory>, and the same error still occur.
I realize that at runtime, Jupyter Notebook produces a .html file and a .json file in /home/<user>/.local/share/jupyter/runtime/, the directory where the permission error is reported. By running ls -l on this directory during runtime, it seems like I (both the user and the group) do not have execute permission on these two files, but have read and write permissions. Is this the cause to my problem? How can I fix this?
(Additionally, I installed Jupyter Notebook using pip inside the conda base environment, and all the above commands are executed in the same environment)
Specs:
Ubuntu version: 21.10
Jupyter Notebook version: 6.4.5
Miniconda version: 4.10.3
Python version: 3.9.5
Web browser: Firefox
Try changing the version of the Jupyter Notebook installed. It worked for me (I am using Ubuntu 22.04 pre release).
Type the following in terminal: pip install notebook==5.6.0
Ubuntu switched Firefox to a snap in 21.10. Snaps can't open files under directories that are hidden in your home directory, like ~/.local.
I have the same issue and am hoping for a solution less drastic than removing the snap and reinstalling Firefox using apt.

Installing a ipykernel and running jupyter notebook inside a virtual env - not using conda

I've hit a dead end trying to solve/debug this issue which doesn't seem like it should be that difficult.
I'm working in Pycharm IDE (not the professional) and I'm working inside a virtual environment let's call it pythonProject and I want to be able to run launch a jupyter notebook in this environment so that it can pick up all the python packages i've installed and configured for this environment.
As I understand it from the documentation, these are the steps I need to take.
My terminal prompt statement:
(pythonProject) oliver#oliver-u20:~/pythonProject$
commands:
python3 -m pip install ipykernel
python3 -m pip install notebook
python3 -m ipykernel install --user --name pythonProject --display-name "Python (pythonProject)"
jupyter notebook
But when I load jupyter notebook, it only shows python3 under kernels.
I tried outputting
jupyter kernelspec list
And get only the base kernel which suggests from this that it's not finding my kernelspec, but I can't seem to figure from the documentation what i'm supposed to do.
Am I missing something?
Ok so I've solved this.
I think there was an install issue with jupyter.
I tried reproducing this in a completely new project and venv and could get the kernel showing.
In the project and venv where I still couldn't, I noticed a discrepancy in the output of my jupyter --paths
In the working venv I could see under data
/home/oliver/.local/share/jupyter
Which is where the kernels I installed are located.
However in the project that wasn't working there was instead:
/home/oliver/snap/jupyter/6/.local/share/jupyter
I'm guessing this snap path is from how I originally installed jupyter on my Ubuntu via the app store - seemed sensible at the time.
So I uninstalled jupyter, restarted my venv and the jupyter --paths has magically changed so that
/home/oliver/.local/share/jupyter
is present and when I start a jupyter notebook at the command line with
jupyter notebook
I can see all my kernels showing!
I found this quite difficult to debug with the documentation and command help outputs so hope someone else finds this useful.

How can I debug a dieing jupyter notebook ipython kernel?

When running my jupyter notebooks, the ipython kernel (Python 3.8, Anaconda) keeps dieing and being restarted.
I want to find what causes it to misbehave. Sadly, I can find no debugging information other than the kernel is dead and restarted.
How can I find more verbose information which may help with post mortem analysis? Is there any error log or something like that?
When you start Jupyter from a console with this command (may from the Anaconda terminal):
jupyter notebook --debug
then it will print extended logging messages. You may also pipe those messages into a separate logfile.txt using
jupyter notebook --debug > logfile.txt 2>&1
Can you try uninstalling all of:
ipykernel
ipython
jupyter_client
jupyter_core
traitlets
ipython_genutils
And then install again. If you're doing this inside a conda env, it might be easiest to create a new environment and start from scratch. Also, if you're going to install with conda, run conda clean -tipsy to clean up conda caches before you start

Anaconda Library Error with Jupyter notebooks for R

I'm trying to write some R code in Jupyter notebooks (I use python too and would like to be able to use the same app for everything), but I'm having some problems...
I'm on a Mac (Yosemite). I installed Anaconda 3, updated Jupyter, then installed RStudio (which includes R essentials). r-irkernel is installed (I assume also through RStudio), version 0.8.11.
When I try to start an R notebook in Jupyter, it starts a kernel and then immediately it dies. The error given is:
Kernel started: 4275a83e-b2b6-40ef-b161-3a7b2ac57c43
Error: .onLoad failed in loadNamespace() for 'pbdZMQ', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Applications/anaconda3/lib/R/library/pbdZMQ/libs/pbdZMQ.so':
dlopen(/Applications/anaconda3/lib/R/library/pbdZMQ/libs/pbdZMQ.so, 6): Library not loaded: #rpath/libzmq.5.dylib
Referenced from: /Applications/anaconda3/lib/R/library/pbdZMQ/libs/pbdZMQ.so
Reason: image not found
Execution halted
What's the best way forwards, please? What am I missing?
Thanks! :)
Alex Mikhalev's answer partially worked for me. However, it also removed notebook and r-essentials.
Their answer was:
conda remove zeromq
conda install zeromq
But, I also needed to install the following as well:
conda install notebook
conda install r-essentials
Try
conda remove zeromq
conda install zeromq
worked for me.
Alas! Other answers have addressed the Anaconda methods so I address the title Jupyter notebooks for R? more generally. Anaconda is nice but always little bit behind. There is also other option to run your Jupyter R notebooks and that is Docker.
Jupyter Docker Stacks
The Jupyter Docker Stacks contains Jupyter R Notebook here available in Github and Docker hub.
You could try it with
$ docker run --rm -it -p 6780:8888 -v "$PWD":/home/jovyan/ jupyter/r-notebook
as in OS X or
$ docker run --rm -it -p 6780:8888 -v "$PWD":/tmp jupyter/r-notebook
as in some other distros or as path required to be set up by your os.
You may find the following threads useful
Show volume files in the GUI of Docker Jupyter notebook
Kernel Error in R Jupyter Notebook due to Anaconda?

ipyparallel with mpi cannot find engines

I'm trying to get a basic ipyparallel environment working using mpi4py as described in the ipyparallel documentation. After starting the ipcluster, I load ipython and try to create a client but it has no IDs and accessing the directview returns a NoEnginesRegistered exception.
Steps I take to get to this point:
Create a new environment: conda create --name=ipyparallel and source activate ipyparallel
Install ipyparallel and mpi4py: conda install ipyparallel mpi4py
Create a new ipython profile: ipython profile create --parallel --profile=mpi
Edit ~/.ipython/profile_mpi/ipcluster_config.py and add c.IPClusterEngines.engine_launcher_class = 'MPIEngineSetLauncher'
Launch cluster with ipcluster start --profile=mpi
Then I launch ipython and run the following:
import ipyparallel as ipp
c = ipp.client(profile="mpi")
c[:] # <-- NoEnginesRegistered exception
Step 5 reports that "Engines appear to have started successfully" and I can see that a process named "mpiexec" is running. Strangely, I tried these same steps on another machine with the same OS and there it worked with no problems. What am I missing?
I solved the problem for anyone coming here with a similar problem. During installation I had added the notebook extension to jupyter's global config. Not sure why that caused this problem but it's fixed now. Outside of a conda environment, I ran:
sudo pip install ipyparallel
sudo jupyter nbextension disable --py ipyparallel
sudo jupyter nbextension uninstall --py ipyparallel
sudo pip uninstall ipyparallel
and then inside the conda environment I can connect to the ipyparallel engines.

Categories

Resources