I referred below link to solve the error of "no module Named cv2":
https://qengineering.eu/install-opencv-4.4-on-raspberry-pi-4.html
I copied manually the cv2 as suggested by the above link as below:
For Python 2:
$ cd ~/opencv/build/lib/ $ sudo cp cv2.so /usr/local/lib/python2.7/dist-packages/cv2/python-2.7
For Python 3:
$ cd ~/opencv/build/lib/python3 $ sudo cp cv2.cpython-37m-arm-linux-gnueabihf.so \ /usr/local/lib/python3.7/dist-packages/cv2/python-3.7
Ensure that you create cv2 dir first if you got error.
I referred below link to solve the error of "no module Named cv2":
https://qengineering.eu/install-opencv-4.4-on-raspberry-pi-4.html
I copied manually the cv2 as suggested by the above link as below:
For Python 2:
$ cd ~/opencv/build/lib/ $ sudo cp cv2.so /usr/local/lib/python2.7/dist-packages/cv2/python-2.7
For Python 3:
$ cd ~/opencv/build/lib/python3 $ sudo cp cv2.cpython-37m-arm-linux-gnueabihf.so \ /usr/local/lib/python3.7/dist-packages/cv2/python-3.7
Ensure that you create cv2 dir first if you got error.
python -c "import cv2" is a quick indicator to import module, you can use it in either of your environments as a check.
My guess is that you should install the module while you are in (cv) environment by running pip install opencv-python at command prompt.
Raspberry PI 4 - ModuleNotFoundError: No module named 'cv2' Error at Boot
linux - python cv2 module not found when triggered by crontab - Raspberry Pi Stack Exchange
python - Cannot find module cv2 when using OpenCV - Stack Overflow
ModuleNotFoundError: No module named 'cv2.cv'; 'cv2' is not a package - Raspberry Pi Forums
Videos
If you install as a user ONLY that user has access.
Install with sudo.
Frankly installing with pip is a poor practice use sudo apt install python3-opencv to install the version in the repository.
Encountering the same question. Been trying to start a python script automatically every time the Raspberry Pi activated, tried every possible way(rc.local, bashrc, crontab and other ways), finally realize that the bashrc and crontab is the most suitable way for my utility.
But both ways return the same Error: Traceback (most recent call last): File "/home/fanshaoqi/chi/plant_phenotyping/Get_Plant_Architecture/0_Main_Script.py", line 2, in import CameraDistance File "/home/fanshaoqi/chi/plant_phenotyping/Get_Plant_Architecture/CameraDistance.py", line 1, in import cv2 ModuleNotFoundError: No module named 'cv2'
This is my .bashrc content: echo Running at boot sudo /usr/bin/python3 /home/fanshaoqi/chi/plant_phenotyping/Get_Plant_Architecture/0_Main_Script.py
This is my crontab content: PYTHONPATH=/home/fanshaoqi/.local/lib/python3.9/site-packages/cv2 LANG=nb_NO.UTF-8 LC_ALL=nb_NO.UTF-8 @reboot sudo /usr/bin/python3 /home/fanshaoqi/chi/plant_phenotyping/Get_Plant_Architecture/0_Main_Script.py
My Raspberry Pi information: fanshaoqi@raspberrypi:~ $ uname -a Linux raspberrypi 6.1.52-v8+ #1679 SMP PREEMPT Fri Sep 8 14:46:04 BST 2023 aarch64 GNU/Linux
fanshaoqi@raspberrypi:~ $ cat /proc/device-tree/model Raspberry Pi 4 Model B Rev 1.4
Pls can someone help me, been stuggling for days... Thank you!
First do run these commands inside Terminal/CMD:
conda update anaconda-navigator
conda update navigator-updater
Then the issue for the instruction below will be resolved
For windows if you have anaconda installed, you can simply do
pip install opencv-python
or
conda install -c https://conda.binstar.org/menpo opencv
if you are on linux you can do :
pip install opencv-python
or
conda install opencv
Link1 Link2
For python3.5+ check these links : Link3 , Link4
Update:
if you use anaconda, you may simply use this as well (and hence don't need to add menpo channel):
conda install -c conda-forge opencv
This happens when python cannot refer to your default site-packages folder where you have kept the required python files or libraries
Add these lines in the code:
import sys
sys.path.append('/usr/local/lib/python2.7/site-packages')
or before running the python command in bash move to /usr/local/lib/python2.7/site-packages directory. This is a work around if you don't want to add any thing to the code.
» pip install opencv-python