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/check_extension_modules.py

returned error:

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

The math.cpython-312-x86_64-linux-gnu.so 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/math.cpython-312-x86_64-linux-gnu.so
/source/python3/build/lib.linux-x86_64-3.12/../../Modules/math.cpython-312-x86_64-linux-gnu.so: /usr/lib/libm.so.6: version `GLIBC_2.29' not found (required by /source/python3/build/lib.linux-x86_64-3.12/../../Modules/math.cpython-312-x86_64-linux-gnu.so)
        linux-vdso.so.1 (0x00007ffe0cfad000)
        libm.so.6 => /usr/lib/libm.so.6 (0x00007fc1bc9dc000)
        libc.so.6 => /usr/lib/libc.so.6 (0x00007fc1bc639000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fc1bcce1000)
CHROOT@ds.kvmx64[/source/python3]#

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 > test.py << 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}")
EOF
/tmp/tmp_python3_for_build/bin/python3.12  test.py   # 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/check_extension_modules.py   # 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.