ModuleNotfoundError when building Python from Source code Main branch

Hello,

I’m experiencing an error repeatedly when trying to build Python from the main branch of the official repository GitHub - python/cpython: The Python programming language .

I have a Python 3.13.7 version in ~/.pyenv/versions already.
Clang version = 19.1.7

System python version = 3.10.12

System = Ubuntu 22.04.5 LTS

Now, I cloned the main branch, checked out a new branch, and tried to build Python from scratch using the following commands.

 ./configure CC=clang --prefix=$HOME/python3.14_1 --enable-optimizations --with-lto --enable-experimental-jit
make -j$(nproc)

With this make command, I’m getting the following error:

.
.
.
Current thread 0x000077860849b740 [_bootstrap_pyth] (most recent call first):
  <no Python frame>
Fatal Python error: make[2]: *** [Makefile:1943: Python/frozen_modules/io.h] Error 1
make[2]: *** Waiting for unfinished jobs....
Failed to import encodings module
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007d427a677740 [_bootstrap_pyth] (most recent call first):
  <no Python frame>
make[2]: *** [Makefile:1952: Python/frozen_modules/genericpath.h] Error 1
Fatal Python error: Failed to import encodings module
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x000075b2c53fc740 [_bootstrap_pyth] (most recent call first):
  <no Python frame>
make[2]: *** [Makefile:1940: Python/frozen_modules/codecs.h] Error 1
make[2]: *** [Makefile:1946: Python/frozen_modules/_collections_abc.h] Error 1
make[2]: *** [Makefile:1937: Python/frozen_modules/abc.h] Error 1
make[2]: *** [Makefile:1949: Python/frozen_modules/_sitebuiltins.h] Error 1
make[2]: *** [Makefile:1958: Python/frozen_modules/posixpath.h] Error 1
make[2]: *** [Makefile:1955: Python/frozen_modules/ntpath.h] Error 1
make[2]: Leaving directory '/home/s265d007/cpython'
make[1]: *** [Makefile:1003: profile-gen-stamp] Error 2
make[1]: Leaving directory '/home/s265d007/cpython'
make: *** [Makefile:1015: profile-run-stamp] Error 2

The entire link of the error: Warp

I tried checking the following command and getting a runtime state error:

./_bootstrap_python -S -c "import encodings; print(encodings.__file__)" \
  PYTHONPATH=./Lib
Fatal Python error: Run filename expected
Python runtime state: preinitialized

I tried the 3.14 branch from the repository but even that’s producing the same error. Is it some issue with some config that I need to change or a known issue? I don’t see much chat about this issue online, though.
Let me know if you need any extra info to debug this issue.
Any input is highly appreciated!

Thanks!