OpenCV install failed ... because I'm out of memory?

Looking at the disc usage analyzer, it says that the modules for OpenCV are taking up 9GBs of memory?
fatal error: can’t write PCH file: No space left on device

How is that possible?
I’m following these steps to reinstall opencv after wrestling with some issues for way too long …
At the make -j4 command, I get about half way through the install and I run out of memory.

What am I doing wrong?

I’d suggest to disable precompiled headers for building. You may use :

Note that it may took a huge disk space depending on the options that you’ve enabled at configure time such as tests, perftests, non-free, …).

let me try that. thank you.
will I need to remove the failed make files first to free up space?

Yes, cleanup the build directory so that you get some disk room again, and just use the install_opencv4.5.0_Jetson.sh from above for a new build.

hmmm … tried just doing a ./install_opencv4.5.0_Jetson.sh … and am getting an 'unexpected token ‘newline’ ’ error.
I’ll step through the commands shortly and report back.

EDIT:
the script’s uninstall commands aren’t working.
i’m assuming a purge command is fine?

alright … opencv finished installing.
trying to run a simple python script and importing cv2.
Am getting this error:
`import cv2

ImportError: No module named cv2`

Is there a path I need to set somewhere?
I’m not finding anything …

Yes, the python install may not be correct.
The following may not be a clean way to do that, but it works for me:

# Note that enabling non_free opencv may lead to issues with python

# Adjust python2 lib..
cd /usr/lib/python2.7/dist-packages/cv2/python-2.7
sudo mv -f cv2.so cv2.so.previous
sudo ln -s /usr/local/lib/python2.7/dist-packages/cv2/python-2.7/cv2.so

# Adjust python3 lib..
cd /usr/lib/python3.6/dist-packages/cv2/python-3.6
sudo mv -f cv2.cpython-36m-aarch64-linux-gnu.so cv2.cpython-36m-aarch64-linux-gnu.so.previous
sudo ln -s /usr/local/lib/python3.6/dist-packages/cv2/python-3.6/cv2.cpython-36m-aarch64-linux-gnu.so

well this is interesting …
I don’t have a ‘cv2’ folder in the dist-packages folder for either version of python …

Should I just create that folder and place the *.so files there?

also, when moving the *.so files, how does the OS know where to find it?
basically, the paths to the files are:

/home/nvidia/Desktop/Python_Work/opencv-4.5.0/release/lib/python3/cv2.cpython-36m-aarch64-linux-gnu.so

and

`/home/nvidia/Desktop/Python_Work/opencv-4.5.0/release/lib/cv2.so’

… i could do this manually … but when running the mv -f command, I get a “mv: cannot stat ‘cv2.so’: No such file or directory” error.

Hi,
Please try to re-flash TX2 and run the script. In a clean system it should work by simply executing the script. Additional steps are not required. Would suggest try a clean system.

which script?

can you please point me to the most up to date walkthrough that includes installing Remote Desktop and VNC (and the dependencies) as well as OpenCV?
That would be helpful.

install_opencv4.5.0_Jetson.sh

Right.
So when I ran that script, I get these errors:
./install_opencv4.5.0_Jetson.sh: line 7: syntax error near unexpected token newline’
./install_opencv4.5.0_Jetson.sh: line 7: <!DOCTYPE html>'

So, instead each command which led to me the post about the *.so files.

well this is interesting …
I don’t have a ‘cv2’ folder in the dist-packages folder for either version of python …
Should I just create that folder and place the *.so files there?
also, when moving the *.so files, how does the OS know where to find it?
basically, the paths to the files are:
/home/nvidia/Desktop/Python_Work/opencv-4.5.0/release/lib/python3/cv2.cpython-36m-aarch64-linux-gnu.so
and
/home/nvidia/Desktop/Python_Work/opencv-4.5.0/release/lib/cv2.so’ … i *could* do this manually … but when running the mv -f` command, I get a “mv: cannot stat ‘cv2.so’: No such file or directory” error.

The content of the file you have is a link.
If you’re not familiar with git, just use:

wget https://raw.githubusercontent.com/AastaNV/JEP/master/script/install_opencv4.5.0_Jetson.sh -O ./install_opencv4.5.0_Jetson.sh
chmod u+x install_opencv4.5.0_Jetson.sh
./install_opencv4.5.0_Jetson.sh

Thanks.
Yes. I still get that same error when running the ./install.... line.

Check that you have at least 4.5 GB free on your disk (sources may use 1GB, and about 3.5GB for the build, 250 MB for the installed files) on the filesystem where you are trying:

df -H -T .

If not enough, be sure to delete your previous opencv sources and build folders.

Filesystem Type Size Used Avail Use% Mounted on
/dev/mmcblk0p1 ext4 30G 20G 8.9G 69% /
none devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs tmpfs 4.2G 318M 3.8G 8% /dev/shm
tmpfs tmpfs 4.2G 377M 3.8G 10% /run
tmpfs tmpfs 5.3M 4.1k 5.3M 1% /run/lock
tmpfs tmpfs 4.2G 0 4.2G 0% /sys/fs/cgroup
tmpfs tmpfs 824M 156k 824M 1% /run/user/1000

Looks like I should have enough … but good idea about doing eventual cleanup.

Please also post the full output log of the script for better advice.

nvidia@nvidia-TX2:~/Downloads$ wget https://raw.githubusercontent.com/AastaNV/JEP/master/script/install_opencv4.5.0_Jetson.sh
--2021-08-23 12:43:19--  https://raw.githubusercontent.com/AastaNV/JEP/master/script/install_opencv4.5.0_Jetson.sh
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.108.133, 185.199.111.133, 185.199.109.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.108.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1989 (1.9K) [text/plain]
Saving to: ‘install_opencv4.5.0_Jetson.sh.1’

install_opencv4.5.0_Jetson.sh.1 100%[=====================================================>]   1.94K  --.-KB/s    in 0.001s  

2021-08-23 12:43:19 (3.56 MB/s) - ‘install_opencv4.5.0_Jetson.sh.1’ saved [1989/1989]

nvidia@nvidia-TX2:~/Downloads$ chmod u+x install_opencv4.5.0_Jetson.sh
nvidia@nvidia-TX2:~/Downloads$ ./install_opencv4.5.0_Jetson.sh
./install_opencv4.5.0_Jetson.sh: line 7: syntax error near unexpected token `newline'
./install_opencv4.5.0_Jetson.sh: line 7: `<!DOCTYPE html>'

Well, I don’t understand why it doesn’t work, but paste this URL:

https://raw.githubusercontent.com/AastaNV/JEP/master/script/install_opencv4.5.0_Jetson.sh

into your favorite web browser and you should see a bash script. Copy the full content and save to file install_opencv4.5.0_Jetson.sh, make it executable and run it.

[EDIT: Ok, if the file exists it is not overwritten. Just delete it before wget. Edited the post above for fixing this:

wget https://raw.githubusercontent.com/AastaNV/JEP/master/script/install_opencv4.5.0_Jetson.sh -O ./install_opencv4.5.0_Jetson.sh

]

no idea why that script didn’t work the first time i’d created it … but it’s building now.
any suggestions on links to remove older opencv versions?