Hey everyone, I’m having trouble getting my Arducam IMX219 working with PiCamera2 inside PyCharm on a Raspberry Pi 4. The camera itself works fine from the command line using libcamera-hello, but as soon as I try to run a script in PyCharm I get an error.
Here’s the code I’m using:
From picamera2 import Picamera2
From libcamera import controls
Picam2 = Picamera2
Picam2.start(show_preview=true)
Picam2.set_controls({"AfMode": controls.AfModeEnum.Continuous})
I’ve been fixing issues left and right and I’m currently stuck on this error:
Since libcamera-hello works at the command line, the camera hardware/driver side is fine - this looks like a Python environment problem. That error means the picamera2 module isn’t installed in whichever Python interpreter PyCharm is using.
A couple of quick checks:
Which Python interpreter is PyCharm set to? (File > Settings > Project > Python Interpreter)
In a terminal, run python3 -c "import picamera2" and see if it works there.
If it imports fine in the terminal but not in PyCharm, PyCharm is pointing at a different environment (a venv, for example).
So yes, libcamera-hello works, so I know the camera is detected. I’ll check the interpreter setting. To be honest I’ve been fixing issues one after another and just got stuck at this ModuleNotFoundError.
The fact that libcamera-hello runs confirms the camera/driver is detected, so we’re dealing with a missing module in PyCharm’s environment rather than a hardware fault.
It covers installing picamera2 and pointing PyCharm at the correct interpreter. Check that page first, especially the part about which Python environment should have picamera2 installed.
Okay, I looked at the interpreter and it seems PyCharm is using a venv. I think that’s why it can’t find picamera2. I’m reading through the README now. Here’s my current script again so we’re on the same page:
From picamera2 import Picamera2
From libcamera import controls
Picam2 = Picamera2
Picam2.start(show_preview=true)
Picam2.set_controls({"AfMode": controls.AfModeEnum.Continuous})
I’m still getting the same ModuleNotFoundError until I sort out the environment.
Right, if PyCharm is using a venv, that venv won’t have picamera2 unless you install it there or point the project at the system Python that already has it. Pick whichever matches the README setup.
One more thing to keep in mind once the import error is gone: the script has a few syntax/usage issues that will bite you next:
From should be lowercase from
Picam2 = Picamera2 assigns the class, but you need to instantiate it: Picam2 = Picamera2()
show_preview=true should be show_preview=True
The immediate blocker is still the missing module though, so fix the interpreter/install first, then clean up those lines. Post back if the error changes after that.