pip install opencv-python
it says:
Successfully installed numpy and opencv-python
Good.
I then run .py:
import cv2
It says:
No module named ‘cv2’
What am I doing wrong?
![]()
pip install opencv-python
it says:
Successfully installed numpy and opencv-python
Good.
I then run .py:
import cv2
It says:
No module named ‘cv2’
What am I doing wrong?
![]()
What OS are you on? ![]()
If your on raspberryPiOS it may be you need to set up an environment where the modules can be sand-boxed for your code.
Hey there, @Bill293536.
As Pixmusix said, it could be down to a Virtual Environment issue, but I’m curious what tutorial are you using?
Every tutorial I have seen on using opencv asks uses to manually download the opencv from github. I’ve never seen any guide recommend installing it via pip.
Pixmusic, Jane,
Thank you.
I will do core opencv again and see if that helps.
![]()
Bill
Pixmusic, Jane,
It works!
I now have a problem.
![]()
from picamera2 import Picamera2
No module named ‘libcamera._libcamera’
What do I do?
![]()
Easy fix, you just need to install it.
From context I think you are using Raspberry Pi Os.
I’ve learned that, as a rule of thumb, if the package has “lib” in the name it probably wants to be installed system wide. On Debian based systems, like RP Os, apt is right tool for this.
sudo apt install python3-libcamera
Pixmusix,
I put the:
sudo apt install python3-libcamera
into the Terminal, and the last item is:
python3-libcamera set to manually installed
Is still fails of:
from picamzero import Camera
![]()
What should I do?
![]()
Hey @Bill293536,
I noticed that your error message occured on a different import than previously. In your last post, you said:
But in this reply, you said the error is on:
echo '/usr/lib/python3/dist-packages' > /home/pi/miniforge3/envs/ultralytics-env/lib/python3.11/site-packages/system-packages.pth
That you replaced the ‘pi’ directory with the home directory that you’re using on the Pi.
Jane,
Thank you.
![]()
Right,
ra5@ra5:~ $ sudo apt install python3-libcamera
The result was:
…python3-libcamera set to manually installed
What should I do?
My .py (Python) was:
from picamzero import Camera
Shell:
…
from ._libcamera import *
ModuleNotFoundError: No module named ‘libcamera._libcamera’
What should I do?
![]()
Bill
pi → ra5
Hey there, Bill,
Are you sure that it’s meant to be:
from picamzero import Camera
If you’re using this guide then the module is listed as picamerazero2 and the import command is:
from picamera2 import Picamera2
Jane,
Thank you.
Uniformity, both give the same result!
ModuleNotFoundError: No module named ‘libcamera._libcamera’
Both:
from picamzero import Camera
and
from picamera2 import Picamera2
What do you think I should do?
![]()
Bill
Hi Bill,
Lets take a step back and make sure all the pieces are in the right place.
The following command will check to see if the _libcamera module is on your system:
dpkg -L python3-libcamera | grep _libcamera
If this returns nothing then -libcamera is not properly installed on your system, in which case you should try installing python3-libcamera again.
Another common cause of this is having your code and modules be on different sides of a virtual environment. The following terminal commands will run a quick test to see if this works from a command line:
python3 -c "import libcamera; print('libcamera ok')"
python3 -c "from picamzero import Camera; print('picamzero ok')"
if everything is set up correctly, these commands should both work without errors from inside of your virtual environment.
Let us know how this goes!
Hi Samuel,
I had tried the commands you listed.
![]()
The first one listed the .libcam
![]()
The second and the third listed:
No module named: libcam
![]()
(ultralytics-env) ra5@ra5
What should I do?
Bill
python3 -c "import libcamera; print('libcamera ok')"
python3 -c "from picamzero import Camera; print('picamzero ok')"
Both give:
ModuleNotFoundError: No module named ‘libcamera._libcamera’
What should I do?
![]()