How can I debug a dieing jupyter notebook ipython kernel? - python

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

Related

VS Code hangs (forever) when connecting to Python Virtual Enviornment for Jupyter interactive

I have VSC 1.71.2 on Windows. When trying to use an interactive python session, it just hangs at the Connecting to kernel step. There are no error messages. I've tried multiple virtual environments and they all do the same (which is nothing). I don't know what I may have done since the last time it's worked until now. I can still activate the Venvs in a terminal.
I'm not really sure what else to try or check.
You can try to update the pyzmq package:
conda update pyzmq
conda update ipykernel

How to import modules into Jupyter Notebook kernel

I am having problems installing modules and then importing them into specific Jupyter Notebook kernels. I want to install them directly into the kernel as opposed to throughout anaconda to separate dependencies in projects. Here is how the problem goes:
I firstly want a package, for example, nltk
I navigate to and activate the conda environment (called python3) and run 'conda install nltk'
I then load that environment into Jupyter using ipykernel with the command 'python -m ipykernel install --user --name python3'
When trying to import the package into the notebook it tells me that it cannot be found
I have been struggling with this for a while. Where am I going wrong? I greatly appreciate all the help.
NOTE: I have somehow managed to install and import many packages into notebooks using the aforementioned process. I'd really like a method to do this in a foolproof manner.
Not entirely clear where things go wrong, but perhaps clarifying some of the terminology could help:
"navigate to...the conda environment" - navigating has zero effect on anything. Most end-users should never enter or directly write to any environment directories.
"...and activate the conda environment" - activation is unnecessary - a more robust installation command is always to use a -n,--name argument:
conda install -n python3 nltk
This is more robust because it is not context-sensitive, i.e., it doesn't matter what (if any) environment is currently activated.
"load that environment into Jupyter using ipykernel" - that command registers the environment as a kernel at a user-level. That only ever needs to be run once per kernel - not after each new package installation. Loading the kernel happens when you are creating (or changing the settings of) a notebook. That is, you choose the kernel in the Jupyter GUI.
Even better, keep jupyter in a dedicated environment with an installation of nb_conda_kernels and Jupyter (launched from that dedicated environment) will auto-discover all Conda environments that have valid kernels installed (e.g., ipykernel, r-irkernel).

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.

The command "jupyter lab" does not work as the file does not exist

I installed Jupyter Lab but cannot launch it (jupyter lab) due to the error: Error executing Jupyter command 'lab': [Errno 2] No such file or directory.
However, it is installed, and is show as one of available subcommands (via jupyter lab):
Available subcommands: bundlerextension console kernelspec lab labextension
labhub migrate nbconvert nbextension notebook qtconsole run serverextension
troubleshoot trust
Why does it not work and is there something I'm missing here? jupyter notebook works without any problems. I also added jupyter serverextension enable --py jupyterlab --sys-prefix according to the documentation on Github, FYI.
My working environment:
jupyter notebook --version # 5.0.0
jupyter version # 4.3.0
#Blazard open the .profile in your home using VIM add the following path
export PATH=$PATH:/home/<user-name>/.local/bin
save it
$ source ~/.profile (Dont forget to do this)
I had the same problem. Installing it over PyCharm IDE solved the problem for me. I am using Windows as an OS. Installing packages over PyCharm works in general better for me than over Windows cmd.
#Blaszard could you try the following
/home/<your-user-name>/.local/bin/jupyter-lab
SOURCE
EDIT
Alternatively, you would have to add /home/<your-user-name>/.local/bin to your PATH variable. However, you should probably just try it manually first and see if that even works at all.
simple solution I found for my mac powerbook is:
go to a working directory in the terminal and then type jupyter lab.
IT WORKS,
We need to find jupyter-lab command. In my case on a mac it is in /opt/local/Library/Frameworks/Python.framework/Versions/3.9/bin/.
I'm using macports so my binaries are in /opt/local/bin. It's on my path:
> echo $PATH
.../opt/local/bin...
I have to create a symbolic link in this directory:
ln -s /opt/local/Library/Frameworks/Python.framework/Versions/3.9/bin/jupyter-lab jupyter-lab

Missing python kernel in jupyter notebook

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.

Categories

Resources