Bug
When I installed and ran Python 3.12 in Ubuntu for the first time, I got a Segmentation fault (Core dumped) error. I downloaded the latest release from the official website. and built Python from the source using the below command:
./configure --enable-optimizations --enable-loadable-sqlite-extensions && make && sudo make altinstall
Debug
To debug this error, I used gdb using the below command:
gdb python3.12
The above command opens the gdb console, then using the run
command, I got into the interactive shell of Python 3.12 and checked the reason for the segmentation fault (core dumped) error. This error can occur for multiple reasons:
- A third-party extension module written in C has crashed.
- Calling external code with built-in
ctypes
module, that crashes. - Something is wrong with the Python installation.
- A bug in Python – should be reported.
In my case, it was Python’s standard library readline
that was crashing.
Fix
To fix this error, I simply installed the libreadline-dev
from the apt
using the below command:
sudo apt install libreadline-dev
And, recompiled the python3.12 from source again:
./configure --enable-optimizations --enable-loadable-sqlite-extensions && make && sudo make altinstall
And that’s it. It worked like a charm.