[OTHER] PICAMERA2 Fails After Latest RPI Bookworm Update/Upgrade
Now receiving the following error from a previously running OK Python program (compiled PYC)
ImportError: /home/pi/.venv/wc/lib/python3.11/site-packages/pykms/pykms.cpython-
311-aarch64-linux-gnu.so: undefined symbol: _ZN3kms17draw_test_patternERNS_12IFr
amebufferENS_7YUVTypeE
Please advise on how to reinstall in an existing Virtual Environment. PICAMERA2 was not installed with SUDO.
Thanks
Sorry, here's the full traceback
Traceback (most recent call last):
File "/mnt/pi_lib/wethCAM/wc/weathercam_V8.10.py", line 67, in <module>
from picamera2 import Picamera2
File "/home/pi/.venv/wc/lib/python3.11/site-packages/picamera2/__init__.py", line 11, in <module>
from .picamera2 import Picamera2, Preview
File "/home/pi/.venv/wc/lib/python3.11/site-packages/picamera2/picamera2.py", line 32, in <module>
from picamera2.previews import DrmPreview, NullPreview, QtGlPreview, QtPreview
File "/home/pi/.venv/wc/lib/python3.11/site-packages/picamera2/previews/__init__.py", line 1, in <module>
from .drm_preview import DrmPreview
File "/home/pi/.venv/wc/lib/python3.11/site-packages/picamera2/previews/drm_preview.py", line 11, in <module>
import pykms
File "/home/pi/.venv/wc/lib/python3.11/site-packages/pykms/__init__.py", line 1, in <module>
from .pykms import *
ImportError: /home/pi/.venv/wc/lib/python3.11/site-packages/pykms/pykms.cpython-311-aarch64-linux-gnu.so: undefined symbol: _ZN3kms17draw_test_patternERNS_12IFramebufferENS_7YUVTypeE
It's not easy to be completely definitive without knowing exactly how you've got to where you are, but it looks to me like you've installed (at least) pykms and picamera2 into your venv using pip. Might that be true?
Anyway, they need to come from the system apt repository otherwise I think they won't update. You should probably try "pip uninstall" on all these packages and hopefully it will fall back to the system versions - which should work.
(The relationship between apt and pip Python packages is tricky - and AFAICT forcing venvs on everyone has not helped. But that's a topic for another time...)
They would need to open up the venv to system wide modules , for it to fall back. You can toggle it in your venv settings file. (Being obtuse because I can't remember it's full name, think it's called pyvenv.??? )
Thanks for the guidance.
As how I got to this point, about 6 months I moved my app to BOOKWORM which meant I put it in a VENV. I didn't look at what was needed for PICAMERA2 (if anything) so would have simply PIP'd into the VENV. All was working find until when I ran APT UPDATE/UPGRADE two days ago.
I've now removed the PICAMERA2 in the VENV PIP and enabled --SYSTEM-SITE-PACKAGES in PYVENV.CFG. Here is the new traceback showing it's using the system level PICAMERA2 but with the same error as well as a missing module BUILTWITH from the KMS module.
Of concern is that it used a VENV KMS but there is none installed at the system level. It also used the VENV PYKMS (2nd exception traceback). It looks like I have a KMS/PYKMS issue.
Thoughts
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/picamera2/previews/drm_preview.py", line 9, in <module>
import kms as pykms
File "/home/pi/.venv/wc/lib/python3.11/site-packages/kms/__init__.py", line 2, in <module>
import builtwith
ModuleNotFoundError: No module named 'builtwith'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/mnt/pi_lib/wethCAM/wc/weathercam_V8.10.py", line 67, in <module>
from picamera2 import Picamera2
File "/usr/lib/python3/dist-packages/picamera2/__init__.py", line 11, in <module>
from .picamera2 import Picamera2, Preview
File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 32, in <module>
from picamera2.previews import DrmPreview, NullPreview, QtGlPreview, QtPreview
File "/usr/lib/python3/dist-packages/picamera2/previews/__init__.py", line 1, in <module>
from .drm_preview import DrmPreview
File "/usr/lib/python3/dist-packages/picamera2/previews/drm_preview.py", line 11, in <module>
import pykms
File "/home/pi/.venv/wc/lib/python3.11/site-packages/pykms/__init__.py", line 1, in <module>
from .pykms import *
ImportError: /home/pi/.venv/wc/lib/python3.11/site-packages/pykms/pykms.cpython-311-aarch64-linux-gnu.so: undefined symbol: _ZN3kms17draw_test_patternERNS_12IFramebufferENS_7YUVTypeE
Some additional info.
The VENV ( (wc) ) version of PYKMS returns the missing symbol error. The non-VENV of PYKMS imports properly.
I can't upgrade the VENV version of PYKMS it must be one of the preinstalled packages. I get an error when I try.
(wc) pi@wethCAM:/media/work/bin $
(wc) pi@wethCAM:/media/work/bin $ python
Python 3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pykms
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/pi/.venv/wc/lib/python3.11/site-packages/pykms/__init__.py", line 1, in <module>
from .pykms import *
ImportError: /home/pi/.venv/wc/lib/python3.11/site-packages/pykms/pykms.cpython-311-aarch64-linux-gnu.so: undefined symbol: _ZN3kms17draw_test_patternERNS_12IFramebufferENS_7YUVTypeE
>>> exit()
(wc) pi@wethCAM:/media/work/bin $
(wc) pi@wethCAM:/media/work/bin $ deactivate
pi@wethCAM:/media/work/bin $
pi@wethCAM:/media/work/bin $ python
Python 3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pykms
>>> exit()
pi@wethCAM:/media/work/bin $
And the attempt upgrading PYKMS inside the VENV
(wc) pi@wethCAM:/media/work/bin $ pip install pykms --upgrade
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
ERROR: Could not find a version that satisfies the requirement pykms (from versions: none)
ERROR: No matching distribution found for pykms
(wc) pi@wethCAM:/media/work/bin $
https://github.com/raspberrypi/pykms
https://github.com/raspberrypi/pykms
The issue that in VENV it returns the error. Outside of VENV, it works. I don't know how to update the version in VENV since it appears to have come with the VENV. I've asked on a Python Forum.
Can you "pip uninstall pykms" in the venv? I believe you should be inheriting it as a site package.
Can you "pip uninstall pykms" in the venv? I believe you should be inheriting it as a site package.
Nope. Likely because it's part of the core Python library. As mentioned above I'm asking on a Python Forum how to update PYKMS in a VENV.
(wc) pi@wethCAM:~ $ pip uninstall pykms
WARNING: Skipping pykms as it is not installed.
(wc) pi@wethCAM:~ $
Maybe there is some confusion, I don't know these packages but just spent a few mins having a look.
There is py-kms that is to do with servers (MS KMS server I think) that is available for the RPi. (You can find the manual for that, just in case your other place gets confused with it)
There is rpi-kms which I assumed you were talking about, in the GitHub I linked above with all the instructions to install and anything else you may need (in a venv (via pip) or sitewide (aka via apt but called python3-kms++ )
Pick the correct one, but neither packages are name pykms other then when used as a module in the rpi-kms one.
On Thu, 21 Aug 2025, 10:34 pm DS256, @.***> wrote:
DS256 left a comment (raspberrypi/picamera2#1311) https://github.com/raspberrypi/picamera2/issues/1311#issuecomment-3212147745
Can you "pip uninstall pykms" in the venv? I believe you should be inheriting it as a site package.
Nope. Likely because it's part of the core Python library. As mentioned above I'm asking on a Python Forum how to update PYKMS in a VENV.
(wc) @.:~ $ pip uninstall pykms WARNING: Skipping pykms as it is not installed. (wc) @.:~ $
— Reply to this email directly, view it on GitHub https://github.com/raspberrypi/picamera2/issues/1311#issuecomment-3212147745, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACYAXN3IPZHRIMHYEFGZ3HD3OY3O5AVCNFSM6AAAAACEOZDZWKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTEMJSGE2DONZUGU . You are receiving this because you commented.Message ID: @.***>
Yes, I think pykms is a confusing name. I believe we use this: https://github.com/tomba/kmsxx (or maybe the repo linked above is a wrapper for this? honestly I'm not too sure)
Either way, it looks like you're importing pykms and the __init__.py file is in your venv (File "/home/pi/.venv/wc/lib/python3.11/site-packages/pykms/__init__.py", line 1, in <module>). This is definitely wrong.
As I said at the start, without knowing exactly how you got your venv into this state it's difficult to give any guaranteed answers. Might you be able to create a new venv? Start with just --system-site-packages and check that you can import pykms/picamera2. Then add the pip packages you need, but not picamera2, pykms or any of the system Python packages. Check as you go that things are still working. Might that be a way forward?
@davidplowman "As I said at the start, without knowing exactly how you got your venv into this state it's difficult to give any guaranteed answers." I'm thinking something is amiss in my VENV. When I create a new TEST environment PYKMS is not there. So how it got into support-packages, but not shown in PIP LIST, is a mystery. Also, I couldn't install PYKMS which means the name for the import is different.
So, based of your's and others advice, and what I'm observing, I going to create a new VENV with --system-site-packages enabled (something I'm going to contemplate for doing with all VENV's)
pi@wethCAM:~ $
pi@wethCAM:~ $ python -m venv .venv/test
pi@wethCAM:~ $ source .venv/test/bin/activate
(test) pi@wethCAM:~ $
(test) pi@wethCAM:~ $ python
Python 3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pykms
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pykms'
>>> exit()
(test) pi@wethCAM:~ $ pip install pykms
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
ERROR: Could not find a version that satisfies the requirement pykms (from versions: none)
ERROR: No matching distribution found for pykms
(test) pi@wethCAM:~ $
Sorry, I'm afraid I'm getting a bit confused. The suggestion was to create a venv with --system-site-packages so I think you need this:
pi@wethCAM:~ $ python -m venv .venv/test --system-site-packages # <- this option
pi@wethCAM:~ $ source .venv/test/bin/activate
(test) pi@wethCAM:~ $
(test) pi@wethCAM:~ $ python
Python 3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pykms
Does that work?
@davidplowman My attempted illustation was there was a PYKMS in the original WC VENV. I assumed a newly create VENV would have it but it doesn't.
So, yes, I'm now having to recreate my VENV as recommended which does not exhibit the same problems with PYKMS since it's coming from the system level implementation
Thanks for the help. I now have to move everything from WC to WC2.
pi@wethCAM:~ $ python -m venv .venv/wc2 --system-site-packages
pi@wethCAM:~ $ source .venv/wc2/bin/activate
(wc2) pi@wethCAM:~ $ python
Python 3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pykms
>>> import picamera2
>>> exit()
(wc2) pi@wethCAM:~ $
Well, that's looking better. Maybe if you can keep a bit of a record of what and how you install things, then you could always send that to us if things go wrong again. Good luck!