DLI Course: "ImportError: cannot import name 'git_revision' " when trying to use CSI camera

Using Jetson Nano BO1 and doing the DLI course - “Getting Started with AI on Jetson Nano”

CSI Camera (Rasberry Pi camera V2.1) connected to 1st slot

Ubuntu 18.04.6 and Docker version 20.10.21

connected to Nano using SSH

Issue: While on the Jupyter Notebook, I was in the csi_camera.ipynb file and was running the code. When running the first code to see if the device was available, it was there. Here is the code:

!ls -ltrh /dev/video*
result:
crw-rw---- 1 root video 81, 0 Aug 23 21:38 /dev/video0

But when I ran the next line of code, I got an error message.
The code:

from jetcam.csi_camera import CSICamera

camera = CSICamera(width=224, height=224, capture_device=0) # confirm the capture_device number

I got this error message:

ImportError Traceback (most recent call last)
in
----> 1 from jetcam.csi_camera import CSICamera
2
3 camera = CSICamera(width=224, height=224, capture_device=0) # confirm the capture_device number

/usr/local/lib/python3.6/dist-packages/jetcam-0.0.0-py3.6.egg/jetcam/init.py in
----> 1 from .camera import Camera

/usr/local/lib/python3.6/dist-packages/jetcam-0.0.0-py3.6.egg/jetcam/camera.py in
1 import traitlets
2 import threading
----> 3 import numpy as np
4
5

/usr/local/lib/python3.6/dist-packages/numpy/init.py in
129 raise ImportError(msg)
130
→ 131 from .version import git_revision as git_revision
132 from .version import version as version
133

ImportError: cannot import name ‘git_revision’

What I’ve tried: is using older versions of docker and then re-updating it. I tried using the fix on this post: “Not Able to Access CSI Camera in Jetson Nano DLI Course Container” but it did not work. I also tried updating Ubuntu.

/usr/local/lib/python3.6/dist-packages/numpy/init .py in
129 raise ImportError(msg)
130
→ 131 from .version import git_revision as git_revision
132 from .version import version as version

Hi @mehulk.khajuria, what version of JetPack-L4T are you running? You can check this with cat /etc/nv_tegra_release on your system, outside of the container.

If you are still running the container, exit it and start a new one. Then inside the container (in its SSH shell), are you able to run python3 -c 'import numpy' ?

hi @dusty_nv I am using jetpack 4.6.1-b110. How do I enter the container? I am able to run that command in the SSH shell but how do I run it in the docker environment? The only command I use in the SSH shell to run the docker is ‘./docker_dli_run.sh’ but I’m unsure how to run the code inside the docker.

Hi @mehulk.khajuria, when you run the ./docker_dli_run.sh script you made, it will start the container and give you an interactive terminal prompt into it - the shell will start with # symbol and you can type bash commands into it like a normal terminal. Press Ctrl+D if you want to exit the container.

Hi @dusty_nv thank you, I found the # symbol and pasted the command you gave. I got an error back:

root@mehul-desktop:/nvdli-nano# python3 -c ‘import numpy’
Traceback (most recent call last):
File “”, line 1, in
File “/usr/local/lib/python3.6/dist-packages/numpy/init.py”, line 131, in
from .version import git_revision as git_revision
ImportError: cannot import name ‘git_revision’

@mehulk.khajuria that’s odd, I just ran nvcr.io/nvidia/dli/dli-nano-ai:v2.0.2-r32.7.1 container on JetPack 4.6, and did not get the same error and was able to import numpy without issue. Also, the container did not have the file /usr/local/lib/python3.6/dist-packages/numpy/init.py, which makes me think that something changed your numpy in the container.

When you exit and restart the container, it’s restored to it’s original state. Have you tried exiting it (press Ctrl+D from the # container prompt) and restarting it using your ./docker_dli_run.sh script?

Hi @dusty_nv I did that and then ran the docker script again and accessed the Jupiter notebook again. I got the same error in the csi camera file again:


ImportError Traceback (most recent call last)
in
----> 1 from jetcam.csi_camera import CSICamera
2
3 camera = CSICamera(width=224, height=224, capture_device=0) # confirm the capture_device number

/usr/local/lib/python3.6/dist-packages/jetcam-0.0.0-py3.6.egg/jetcam/init.py in
----> 1 from .camera import Camera

/usr/local/lib/python3.6/dist-packages/jetcam-0.0.0-py3.6.egg/jetcam/camera.py in
1 import traitlets
2 import threading
----> 3 import numpy as np
4
5

/usr/local/lib/python3.6/dist-packages/numpy/init.py in
129 raise ImportError(msg)
130
→ 131 from .version import git_revision as git_revision
132 from .version import version as version
133

ImportError: cannot import name ‘git_revision’

Strange…what does pip3 show numpy show for you when run inside the DLI container? This is what mine shows:

# pip3 show numpy
Name: numpy
Version: 1.19.5
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email: None
License: BSD
Location: /usr/local/lib/python3.6/dist-packages
Requires:

What does your docker_run_dli.sh script look like? Mine is like this:

sudo docker run --runtime nvidia -it --rm --network host \
  --volume ~/nvdli-data:/nvdli-nano/data \
  --volume /tmp/argus_socket:/tmp/argus_socket \
  nvcr.io/nvidia/dli/dli-nano-ai:v2.0.2-r32.7.1

Hi @dusty_nv I think I found the issue but I’m unsure how to solve it. When I open the docker run dli.sh script on the jetson I see this:

sudo docker run --runtime nvidia -it --rm --network host --volume ~/nvdli-data:/nvdli-nano/data --volume /tmp/argus_socket:/tmp/argus_socket --device /dev/video0 nvcr.io/nvidia/dli/dli-nano-ai:v2.0.2-r32.7.1

But when I go and run the command you gave me earlier to check the jetpack version I see this:

mehul@mehul-desktop:~$ cat /etc/nv_tegra_release

R32 (release), REVISION: 7.4, GCID: 33514132, BOARD: t210ref, EABI: aarch64, DATE: Fri Jun 9 04:25:08 UTC 2023

Which shows R32.7.4 whereas in the docker run dli.sh script it is shown as R32.7.1. I think that might be causing the error.

Here is what pip3 show numpy command gives me:

root@mehul-desktop:/nvdli-nano# pip3 show numpy
Name: numpy
Version: 1.19.5
Summary: None
Home-page: None
Author: None
Author-email: None
License: None
Location: /usr/local/lib/python3.6/dist-packages
Requires:
root@mehul-desktop:/nvdli-nano#

The r32.7.1 version of the container should run on r32.7.4, they are compatible with each other. However, I’m unsure why your numpy is different from the numpy that I (and presumably everyone else) see’s in that same container…

You have the same version of numpy (1.19.5), but the other package info is different/missing. Can you try running pip3 install --upgrade --force-reinstall --verbose numpy inside your container? Then try importing numpy again (without exiting the container in between those steps)

Hi @dusty_nv I ran the command inside the container and after that I tried to import numpy and it gave no error. I then exited the container and ran the dli nano script again and got the same error in the csi file on jupyter notebook. I then went back to the container and ran the import command again but it gave an error now. Here is the error:

Traceback (most recent call last):
File “”, line 1, in
File “/usr/local/lib/python3.6/dist-packages/numpy/init.py”, line 131, in
from .version import git_revision as git_revision
ImportError: cannot import name ‘git_revision’

I ran the other command again “pip3 show numpy” and it shows the same thing as before:

root@mehul-desktop:/nvdli-nano# pip3 show numpy
Name: numpy
Version: 1.19.5
Summary: None
Home-page: None
Author: None
Author-email: None
License: None
Location: /usr/local/lib/python3.6/dist-packages
Requires:

I’m going back through the process to see if there was anything odd with the redownload for numpy. The only warning I saw was this:

warning: no previously-included files matching ‘.pyo’ found anywhere in distribution
warning: no previously-included files matching '
.pyd’ found anywhere in distribution
warning: no previously-included files matching ‘.swp’ found anywhere in distribution
warning: no previously-included files matching '
.bak’ found anywhere in distribution
warning: no previously-included files matching ‘*~’ found anywhere in distribution
warning: no previously-included files found matching ‘LICENSES_bundled.txt’

It’s strange, because I just pulled again nvcr.io/nvidia/dli/dli-nano-ai:v2.0.2-r32.7.1 this morning, and do not have the numpy issue like you do. And by exiting/restarting your container, it shows that different version of numpy is in your container image.

Can you try doing a sudo docker pull nvcr.io/nvidia/dli/dli-nano-ai:v2.0.2-r32.7.1 and see if it downloads and updates to the image?

Otherwise, I would just apply the numpy fix like you have done with pip3 install --upgrade --force-reinstall --verbose numpy you can then save these changes you made with docker commit

@dusty_nv I think that reinstall fix works as the “pip3 show numpy” gives me this:
root@mehul-desktop:/nvdli-nano# pip3 show numpy
Name: numpy
Version: 1.19.5
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email: None
License: BSD
Location: /usr/local/lib/python3.6/dist-packages
Requires:

But the issue remains that once I leave the docker then the changes won’t stay. I tried your “docker commit” but it does not recognize it and gives me this:

bash: docker: command not found

This needs to be run in a separate terminal (outside of container), while the container you have fixed numpy in is still running. So after you have made the numpy fix inside the DLI container, open a new SSH terminal, and then get the ID of the container that’s running with sudo docker ps:

$ sudo docker ps
CONTAINER ID   IMAGE                                           COMMAND                  CREATED          STATUS         PORTS     NAMES
ff62e633a6cf   nvcr.io/nvidia/dli/dli-nano-ai:v2.0.2-r32.7.1   "/bin/sh -c '/bin/ba…"   11 seconds ago   Up 9 seconds             busy_hugle

Then run something like this (substituting the unique ID of the container printed above):

$ sudo docker commit ff62e633a6cf my_dli_container:r32.7.1

Then change your docker_dli_run.sh script and replace nvcr.io/nvidia/dli/dli-nano-ai:v2.0.2-r32.7.1 in it with the name of your new container (my_dli_container:r32.7.1) so that it runs that one instead.

I made the new container and got a “sha256” followed by a long list of numbers. I then logged onto the nano and clicked on the script docker_dli_run,sh and it opened a terminal and showed a “E325:ATTENTION” saying that there was a swap file with the same name and gave me multiple options. I just went with edit anyway and tried to replace the line with the new container name but it is not letting me edit it. Is there a command that I could do instead?

If you have desktop GUI open, did you try opening the docker_dli_run.sh script with GEdit (“Text Editor”)

The easiest terminal text editor is nano, you can install that with sudo apt-get install nano if you don’t already have it, and to open the file you can run nano /path/to/your/docker_dli_run.sh

@dusty_nv I installed nano and was able to edit it that way. I just did the final step and everything works fine now. Thank you so much for your help and I appreciate you for taking the time to help me on this and teach me some new stuff. I’ll mark the one where you mention reinstalling numpy and commit it.

Glad you got it working @mehulk.khajuria!! 😊 thanks for bearing with me there working through that. I’m still not sure why your dli-container image was different with numpy, but regardless glad we were able to get it running!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.