This post is about how to add and enable variable inspector in Jupyter Notebook and JupyterLab.
If you are working on data science projects using Python, you must know some editors like Spyder and Jupyter Notebook. I like both of them, for some large project or some research works with other team members, I prefer to use Spyder, as it is more like pure code oriented. But sometimes, I need to update my recent work or some algorithms with demo to my supervisor, Jupyter Notebook is better, as I am able to add code blocks as well as some description of each section and make it more informative. However, at the very beginning when I start using Jupyter Notebook, I found a inconvience that bother me the most, is there is no variable explorer in Jupyter Notebook, which makes life way easier if you want to check the data type and shape of the variables or sometimes you get an error and saying the variables’ shapes are not matched when you want to stack two arraies or do some operations. At this time, I just hope there is a variable inspector just like the variable explorer at the top right corner of the Spyder. Don’t get me wrong, I know the Google Colab (sometimes we also call it notebook) has the variable explorer function, I just mean the Jupyter Notebook at here.
Fortunately, there are solutions to allow you to freely check any variable types and shape in Jupyter Notebook and JupyterLab. Now, let’s start.
1. Jupyter Notebook
To enable the variable inspector in Jupyter Notebook, I found one solution is very helpful and works for me from a stack overflow question, one answer updated at May 17 2017. To enable it for the user environment, I guess it is the base Python environment.
Install:
User
From Terminal window install this variable inspector extension.
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
Virtual environment
If you have created a virtual Python environment with specified Python version and some other libraries you added, activate that environment and enter the following commands. I tested this one and it works.
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --sys-prefix
Activate/Enable:
If you have installed this Jupyter Notebook extension, then we just simply activate or enable it by:
jupyter nbextension enable varInspector/main
Test
After enabling it, once you restart your terminal and open your Jupyter Notebook, you should be able to find a new icon next to that small keyboard button (shortcut button), that means you have successfully installed and enabled this variable inspector extension in Jupyter Notebook. Double-click that button, a window pops out and that is your variable explorer in Jupyter Notebook, when you import a CSV data or assign values to any variable, you should able to check the data type, shape and values of it.
2. JupyterLab
If you need to work on several different Notebooks at the same time, probably JupyterLab is better. For JupyerLab, there is a extension available on GitHub or you can directly search variable inspector in JupyterLab and add/install as extension. Here I will show how to install it through terminal window. GitHub link.
In the base environment or a pre-built virtual environment, this extension can be simply added using pip.
pip install lckr-jupyterlab-variableinspector
That’s it, pretty easy right. Then you can open JupyterLab and have a try. Right click at anywhere in JupyterLab, and the last option, it should be
Then click it, there will be a new tab next to your current Notebook tab, and you can find every variables type, shape and values there.
Till now, you have enabled the variable inspectors in both Jupyter Notebook and JupyterLab.