Qengineering / Jetson-Nano-Ubuntu-20-image

Jetson Nano with Ubuntu 20.04 image
https://qengineering.eu/install-ubuntu-20.04-on-jetson-nano.html
BSD 3-Clause "New" or "Revised" License
702 stars 74 forks source link

importing OpenCV2 (cv2) in local Python environment vs Jupyter Environment #58

Open gpullela opened 10 months ago

gpullela commented 10 months ago

Hi,

I am using your Ubuntu 20.04 image and it's great! I am confused about one thing though - it says that I have OpenCV 4.8.0 on my jetson nano (using jtop and verified through Python 3.8.10 shell), but when I try to import and check its version on jupyter lab, it says version "4.5.3".

Can you help me figure out how to use the correct OpenCV package?

Thank you!

Qengineering commented 10 months ago

When you check the version of OpenCV in jtop or the Python 3.8.10 shell, you are likely seeing the version that is installed globally on the system. However, when you import OpenCV in Jupyter Lab, you are importing a different version that is installed in Jupyter Lab's virtual environment.

To confirm this, you can try activating the virtual environment that Jupyter Lab is using and then checking the version of OpenCV. To activate the virtual environment, run the following command in the Jupyter Lab terminal:

source activate jupyter

Once the virtual environment is activated, you can check the version of OpenCV using the following command:

python -c "import cv2; print(cv2.__version__)"

If the version of OpenCV that is reported in the Jupyter Lab terminal is different from the version that is reported in jtop or the Python 3.8.10 shell, then this confirms that you have multiple versions of OpenCV installed.

There are a few possible reasons why you might have multiple versions of OpenCV installed. One possibility is that you installed OpenCV manually from source, and then later installed a pre-built package of OpenCV using a package manager like apt or pip. Another possibility is that you are using a third-party library that depends on a different version of OpenCV than the one that is installed globally on the system.

If you are not sure why you have multiple versions of OpenCV installed, or if you are having problems using OpenCV in Jupyter Lab, you may want to try uninstalling the version of OpenCV that is installed in Jupyter Lab's virtual environment and then reinstalling OpenCV from source.