Python interpretor tried to run .so for target machine in PYTHONPATH during cross-compiling

I got error during cross-compiling:

_PYTHON_PROJECT_BASE=/source/python3 _PYTHON_HOST_PLATFORM=linux-x86_64 PYTHONPATH=/source/python3/build/lib.linux-x86_64-3.12:./Lib  _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata__linux_x86_64-linux-gnu /tmp/tmp_python3_for_build/usr/bin/python3.12 ./Tools/build/

returned error:

Traceback (most recent call last):
  File "/source/python3/./Tools/build/", line 25, in <module>
    import pathlib
  File "/source/python3/Lib/", line 20, in <module>
    from urllib.parse import quote_from_bytes as urlquote_from_bytes
  File "/source/python3/Lib/urllib/", line 36, in <module>
    import math
ImportError: /usr/lib/ version `GLIBC_2.29' not found (required by /source/python3/build/lib.linux-x86_64-3.12/
Makefile:1145: recipe for target 'checksharedmods' failed
make: *** [checksharedmods] Error 1

The requires a glibc with version 2.29 which only exists on the target machine. (note. both build machine and target machine are x86_64 architecture, but they have different toolchain and glibc)

CHROOT@ds.kvmx64[/source/python3]# /usr/local/x86_64-pc-linux-gnu/x86_64-pc-linux-gnu/sys-root/usr/bin/ldd /source/python3/build/lib.linux-x86_64-3.12/../../Modules/
/source/python3/build/lib.linux-x86_64-3.12/../../Modules/ /usr/lib/ version `GLIBC_2.29' not found (required by /source/python3/build/lib.linux-x86_64-3.12/../../Modules/ (0x00007ffe0cfad000) => /usr/lib/ (0x00007fc1bc9dc000) => /usr/lib/ (0x00007fc1bc639000)
        /lib64/ (0x00007fc1bcce1000)

I noticed that the argument: PYTHONPATH=/source/python3/build/lib.linux-x86_64-3.12 played a crucial role in this error. By removing the /source/python3/build/lib.linux-x86_64-3.12 from the PYTHONPATH. The cross-compile works well on one x86_64 platform. However, removing it will cause failure on all other non-x86_64 platforms. Given the tries above, I believe the /source/python3/build/lib.linux-x86_64-3.12 is a required argument for cross-compiling python properly.

Test: run python script with PYTHONPATH=/source/python3/build/lib.linux-x86_64-3.12 will fail during import math

cat > << EOF
import math
# Define the number for which you want to calculate the square root
number = 16.0  # You can change this number to any value you like
# Calculate the square root
square_root = math.sqrt(number)
# Print the result
print(f"The square root of {number} is {square_root}")
/tmp/tmp_python3_for_build/bin/python3.12   # succeed
_PYTHON_PROJECT_BASE=/source/python3 _PYTHON_HOST_PLATFORM=linux-x86_64 PYTHONPATH=/source/python3/build/lib.linux-x86_64-3.12:./Lib  _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata__linux_x86_64-linux-gnu /tmp/tmp_python3_for_build/bin/python3.12 ./Tools/build/   # failed

According to the document, the PYTHONPATH is used to tell python interpretor where to find the python modules. These .so in the PYTHONPATH looks weird since I suppose that there should be only python modules like .py, .pyc or .pyo in the folder specified by PYTHONPATH.

I wonder if there is a bug with cross-compiling a identical architecture with different glibc.

How can I fix this cross-compiling problem? Why would the python interpretor on the build machine tried to run the .so in the PYTHONPATH? Thank you.