Closed abhisheeekkk closed 1 year ago
@abhisheeekkk ,
That's strange. Somehow OpenCV couldn't find your Python3. When you run $ cmake -D CMAKE_BUILD_TYPE=RELEASE ...(etc)
it ends with an overview like the one below.
Here you see the necessary Python3 folders. If the
cmake
command doesn't come with this information, it will not generate a Python3 version. Second, less common cause, the installation is done in the /usr/lib/python3/site-packages
folder instead of the /usr/lib/python3/dist-packages
. Hence the -D PYTHON3_PACKAGES_PATH=/usr/lib/python3/dist-packages
option
Hi @Qengineering,
I found the root cause of the issue, which was causing this strange behavior, So yesterday I wasn't focusing much on logs, because every line was showing SUCCESS, but today I thoroughly inspected the logs and found that, after these below exact lines in the Terminal,
-- ocv_init_download: OpenCV source tree is not fetched as git repository. 3rdparty resources will be downloaded from github.com by default.
-- Detected processor: aarch64
-- Found PythonInterp: /usr/bin/python2.7 (found suitable version "2.7.17", minimum required is "2.7")
-- Found PythonLibs: /usr/lib/aarch64-linux-gnu/libpython2.7.so (found suitable exact version "2.7.17")
-- Found PythonInterp: /usr/bin/python3 (found suitable version "3.7.5", minimum required is "3.2")
-- Found PythonLibs: /usr/lib/aarch64-linux-gnu/libpython3.7m.so (found suitable exact version "3.7.5")
I was getting this error, but compilation didn't stop and moved so fast that it was easy to miss in a blink.
line 16, in <module>
from . import multiarray
ImportError: cannot import name multiarray
During handling of the above exception, another exception occurred:
........................
So, it was numpy all along, Even I was not able to uninstall and reinstall using pip3,
[Error was - Not uninstalling numpy at /usr/lib/python3/dist-packages, outside environment /usr ]
So I searched regarding this issue online and found some stackoverflow and askubuntu articles regarding this, particularly these one two helped me.
commands that I executed to solve the above error:
sudo apt remove python-numpy
sudo pip uninstall numpy --isolated
sudo -H python3.7 -m pip uninstall numpy
sudo apt purge python3-numpy
sudo -H python3.7 -m pip install --upgrade pip
sudo -H python3.7 -m pip install numpy
After verifying that numpy has been installed successfully, I tried to import it in the python3 script and it exported successfully, I cleaned the components which I installed using your script, like OpenCV, opencv_contrib folders, corrasponding zip files and shell file (OpenCV-4-6-0.sh)
Then I ran these commands according to your article and provided swap size.
# a fresh start, so check for updates
$ sudo apt-get update
$ sudo apt-get upgrade
# install nano
$ sudo apt-get install nano
# install dphys-swapfile
$ sudo apt-get install dphys-swapfile
# enlarge the boundary (4.5.2 and higher)
$ sudo nano /sbin/dphys-swapfile
# give the required memory size
$ sudo nano /etc/dphys-swapfile
# reboot afterwards
$ sudo reboot
after these commands I ran commands till here, because I had to make one change in the script because I am using Jetson Xavier not nano,
# check your memory first
$ free -m
# you need at least a total of 8.5 GB!
# if not, enlarge your swap space as explained in the guide
$ wget https://github.com/Qengineering/Install-OpenCV-Jetson-Nano/raw/main/OpenCV-4-6-0.sh
$ sudo chmod 755 ./OpenCV-4-6-0.sh
After running commands till here, I opened the script in the text editor and changed this line -D CUDA_ARCH_BIN=5.3 to -D CUDA_ARCH_BIN=7.2 Reference(https://developer.nvidia.com/cuda-gpus)
After the above change, I ran these commands according to your article:
$ ./OpenCV-4-6-0.sh
# once the installation is done...
$ rm OpenCV-4-6-0.sh
# remove the dphys-swapfile now
$ sudo /etc/init.d/dphys-swapfile stop
$ sudo apt-get remove --purge dphys-swapfile
# free the allocated memory
$ sudo rm /var/swap
# just a tip to save an additional 275 MB
$ sudo rm -rf ~/opencv
$ sudo rm -rf ~/opencv_contrib
To verify now I tried to import OpenCV for both python2.x.x. and python3.x.x and it was now not throwing errors.
Thank you @Qengineering, for your wonderful article and support!
@abhisheeekkk
Great!
Hi there, I have downloaded the Jetpack 4.6.3, in my xavier NX, now when I try to run the script that you provided in your Article, OpenCV-4-6-0.sh After successful building and making by the script, I was not able to import python in python3, but was able to import it in python2.x
In the below logs you'll see that python3 is not in the interpreter but python2 is available. refer below image
Terminal Logs
Can you please suggest what should I do?, I have followed all the steps as you mentioned. Thanks