How to Install Jupyter Lab on JP4.4

Hello folks;

I got Jupyter Lab working on a clean copy of JP4.4 on my Jetson Nano (B01). Here are the steps I followed, hopefully they help you as well. It seems like everyone is being pointed to the JetBot scripts, or this link as an answer when asking for help on Jupyter Lab installations. I can’t tell you why, but they don’t work on JP4.4.

Step 1 Install pip and python3-dev
I’m not advanced enough in Linux to know if all these commands can be run in one command line or not, but here they are one-by-one:

$ sudo apt install -y python3-pip

$ sudo apt install -y pythond3-dev

Step 2 Install virtualenv virtualenvwrapper

$ sudo pip3 install virtualenv virtualenvwrapper

Next you will need to edit your bashrc script. I’m using vi for this, but if you’re more comfortable with nano, then simply replace vi with nano in the command below:

$ sudo vi ~/.bashrc

Add the following lines to the very bottom of the script:

export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh

Save and exit out.

Next reload your ~/.bashrc by running the following command:

$ source ~/.bashrc

Step 3 Set up a virtual environment

The name of my virtualenv is going to be deepstream5, the whole point of what I’m doing is so that I can run the python examples provided in deepstream sdk on Jupyter Lab.

$ mkvirtualenv deepstream5 -p python3

You will be automatically signed into the virtualenv, if you don’t see it then simply run:

$ workon deepstream5

Step 4 Configuring the Virtual Environment

Make sure you’re in your virtual environment before proceeding with the next steps…

Install node.js, follow the instructions found on this link. It’s been answered in another forum post: Install Node.js

Step 5 Install Jupyter Lab

Note: Before proceeding, it’s important to note that Jupyter (Jupyter Notebook) and Jupyter Lab are different. Jupyter Lab has Jupyter Notebooks, but not vice-verse. I like Jupyter Lab way more than Jupyter notebooks. Please make sure you know what you’re installing.

$ pip install jupyterlab

Now you can run the config:

$ jupyter lab --generate-config

Hopefully this works for you as well!

Major inspiration for these instructions come from Andrew Bibian, he’s got a github.io page that talks about this in further detail, here is a link: Running Jupyter Notebooks on the Jetson Nano (via https)

NOTE:

If you start jupyter lab before having a web browser open, you’ll get the following error in the terminal window where you started the service:

Error: Can't initialize nvrm channel 

To avoid getting it, have a web browser open first; before you start the jupyter lab service. You won’t get that error if you first do this.

Cheers!

1 Like

It’s great! Thanks for your sharing to community!

The procedure works on Jetson Nano 2GB. But the default (with the Jetson Nano 2GB Developer Kit SD Card Image) opencv 4.1.1 was missing in the environment, as nvcr.io/nvidia/l4t-ml:r32.4.4-py3 did. is there a way for us to make the default opencv 4.1.1 work along with “the installed Jupyter Lab”? Thanks.

I think the question your asking is this:

Can you run multiple versions of OpenCV, without affecting the default version?

The answer is yes. However;

  • You need to set up a virtual environment
  • Setting up OpenCV in a virtual environment is complex. It’s doable, but it’s a manual process. All of the scripts you’ll find out there are for installing / upgrading OpenCV are for the base application. To my knowledge, these scripts do not work when installing inside a virtual environmnet.

If you’re still interested, pyimagesearch.com has a very detailed article:

How to configure your NVIDIA Jetson Nano for Computer Vision and Deep Learning

It goes through a step by step process of setting up a virtual enviroment as well as installing OpenCV and Tensorflow to work inside this environment.

Once inside the virtual environment, you’ll have to set up jupyter lab. The instructions above will work. However, one issue I’ve found is with nodejs.

You need an updated version of nodejs for jupyter to work correctly. I haven’t had much success setting up nodejs inside a VE, but I haven’t followed the pyimagesearch article. They may have this resolved already.

Hope that helps.

At this moment, I just want that the default opencv (4.1.1) can be used/imported within the installed Jupyter. Sorry for the confusion. My original question has been revised accordingly.

An update on 11/21/2020,
It shows 4.1.1 when running python3 -c “import cv2; print(cv2.version)” BEFORE running mkvirtualenv deepstream -p python3.
However, No module named ‘cv2’ will be returned when running python3 -c “import cv2; print(cv2.version)” AFTER running mkvirtualenv deepstream -p python3.
I could not find a reason after checking the content of /usr/local/bin/virtualenvwrapper.sh
Any suggestions? Thank you.

Thanks.