Modul _ctypes not found

File “/usr/local/lib/python3.12/ctypes/init.py”, line 8, in
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named ‘_ctypes’

The use of /usr/local suggests that this is a private build of python.
Given that I suspect whoever built that for you did not have all dependencies that python’s modules needs.
You should ask for a fix from the maintainer if that is the case.

Would I also be correct in guessing that your distro does not support python 3.12 yet?

I would guess it’s a custom CPython build and the ctypes module just wasn’t built, probably due to missing libffi. “./configure” script output could be helpful here.

You are both right. My distro is MX-Linux. The included Python is 3.9.

I did the build at 2024-04-27 so I don’t have got the output anymore.

Any hints for this situation?

Rebuild, with all required development libraries present, in this case specifically libffi.

Interesting, I have a similar issue.

My system is also MX-Linux (23.4). As you know, the APT repository is common to all Debian-derived distros, like MX-Linux, Ubuntu and so on. It is currently only up to python3.11.

Wanting to have the latest python on my machine, I installed python3.12 from python.org, without any issues, and it included ctypes. However my installation of python3.13 did not come with ctypes.

Installing libffi-dev from the APT repository did not fix this. (There is no library specifically called ‘libffi’ in APT).

I will try a re-installation of 3.13, or roll back to 3.12 or 3.11.

As you know, the APT repository is common to all Debian-derived distros, like MX-Linux, Ubuntu and so on. It is currently only up to python3.11.

Sorry, no, Debian derivatives don’t share the same package repository. Also I run actual Debian (not a derivative) and have Debian’s Python 3.13 package installed. Ubuntu has 3.13 too though…

https://packages.debian.org/python3.13
https://packages.ubuntu.com/python3.13