Module Error for picamera2

I’ve been trying to test out manipulating my Raspberry Pi Camera Module 3 through Thonny but I’ve been getting the "ModuleNotFoundError: No module named ‘picamera’ " and I’m not quite sure why. It’s my first time using this so bare with me, this is what I’ve done:

I used these commands to install OpenCV:
sudo apt-get install python3-pip python3-virtualenv
mkdir project
cd project
python3 -m pip install virtualenv
python3 -m virtualenv env
source env/bin/activate
sudo apt install -y build-essential cmake pkg-config libjpeg-dev libtiff5-dev libpng-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libfontconfig1-dev libcairo2-dev libgdk-pixbuf2.0-dev libpango1.0-dev libgtk2.0-dev libgtk-3-dev libatlas-base-dev gfortran libhdf5-dev libhdf5-serial-dev libhdf5-103 libqt5gui5 libqt5webkit5 libqt5test5 python3-pyqt5 python3-dev
pip install “picamera[array]”
pip install opencv-contrib-python

Then I went to sudo nano boot/firmware/config.txt > camera_auto_detect=0 >then added dtoverlay=imx708 under [all]
So that allowed me to use the camera without python and it works.

I went to Thonny, I changed (maybe I didn’t do it right) the interpreter to the virtual enviornment that I have OpenCV, the picamera[array]
I tried to import Opencv and tell me the version of it and it worked.

so I copy-pasted this code:


and tried this one:

then I opened a new terminal in the raspberry and tried to install the PiCamera without the virtual environment and this was the result


So it’s definitely installed somewhere, but how could I use it in Thonny or how can I reinstall it in the virtual environment I created?

Btw I’m using a Raspberry Pi 4 B

Hi Caroline,

This is a copy paste of my solution on your other forum post. Hopefully this gets it fixed for you!

Hopefully this is an easy one. Python is case sensitive so the libraries you are importing need to be spelled exactly as expected including uppercase letters.

so in your import line:

from picamera import Picamera, Preview

You may be running into issues due to how you have written this line.

try replacing this with:

from picamera import PiCamera, Preview

The difference being “PiCamera” has what I think is the correct letter case for importing this library.

Hope this helps!
Sam

1 Like

Hi Sam!! Thank you so much for replying! Unfortunately, I’m getting this error


(I tried it with PiCamera2 and I’m still getting a “ModuleNotFoundError”)

I’m aware that I have Picamera2 installed but it’s not within the virtual environment that I have been using, I had followed these suggestions (https://forums.raspberrypi.com/viewtopic.php?t=361758) but it still does not work :smiling_face_with_tear: and then I also had an “internal error” pop up while trying to download picamera2 through Thonny, along with the installation error that it has been giving me.

I’m at a loss

1 Like

I already have a bit of an update. Good news, PICAMERA2 IS INSTALLEDDDDD :partying_face: … bad news, it gave me another error, which was another Module Error but for Libcamera and i installed it through Thonny … now I have MORE errors… I’m losing my absolute mind.

1 Like

The dependency rabbit-hole is deep @Caroline269834 :smiling_face_with_tear:
It looks like the next module to install (within your selected environment) might be pykms

2 Likes

It definitely worked but we’re on to new errors now :rofl:
The Raspberry Pi God’s have not been too kind to me

That’s not a great error. Its indicating that your PiCamera2 module install may not have gone as well as you thought as your code can’t find it.

You may need to go back through that process again.

Before you do that though. I know I suggested you change your PiCamera import line before but for Picamera2 I think the correct case format would be:

from picamera2 import Picamera2, Preview

Each imported module loves to use their own syntax for how its imported so maybe that will help.

1 Like

Thank you! I did correct it but now there’s a new module not found ‘PyQt5’, and I have it installed already but I guess I’m circling back to trying to redirect the modules to the virtual environment being used. (My best guess, I don’t understand where I’ve gone wrong)

Is it normal to be experiencing these many errors? I know I am a newbie but geeez…

3 Likes

Some errors alone this line are always a possibility as its not the simplest process to make sure all the libraries you need are installed. Have you been following a tutorial on this to find the correct libraries that you could send us?

If you can we may be able to trace through that and find a step that’s incorrect or missing?

2 Likes

I’ve been picking at some videos, links and forums. I don’t have a specific tutorial. I tried write up a list of everything I’ve done with the links and codes used (at least what I can remember) in word. It is a bit long so that’s why I attached it as a pdf. If that isn’t allowed then I can copy-paste it to another comment.

Libraries installed.pdf (378.1 KB)

Also, thank you for taking the time to answer my questions, I do not have a mentor for my Capstone project and I have a month left to be able to get the entire project done so I apologize for the long messages and probably very dumb questions but I appreciate it truly.

2 Likes

Hey Caroline,

Looks like you have been more than thorough with your research and nothing stands out as a obviously missing in the steps you have taken so far. Its clear you have put a ton of time into this already.

I back tracked a bit through this thread and had a look at the Raspberry Pi forum post you followed for setting up a picamera2 in a virtual environment and unfortunately it looks like that method doesn’t seem to work with qt5. That would explain why it cant detect the ‘PyQt5’ module. It’s buried as a disclaimer somewhere in the middle of the commands, easy to miss.

Can I ask why your trying to run this all through a virtual environment? It seems like all these library complications stem from this one step. Would it maybe be best to work on this in a local environment first and then transition to a virtual environment once you get everything else working?

2 Likes

I think I did try to do it locally but I had “pip installs” that I was trying to run through the terminal but quickly learned that pip is not used the same way like before and I was unsure if using “sudo apt-get” (or something similar with ‘apt’) would’ve worked (I can’t remember if I also tried it), and when I was researching about virtual environments, a lot of people said that it was a good practice🥲

A little bit of an update though, I ditched Thonny and copy-pasted the same code in Visual Studio Code and it worked! Next new goals are trying to calibrate the camera (it’s already not going great lol) and making it recognize an ArUco marker! The real battle begins now :sweat_smile:

2 Likes

:partying_face: Nice one @Caroline269834 :partying_face:

Good luck!! :+1:

2 Likes