My issue on mac was because I uncommented export ARCHFLAGS="-arch x86_64" in the .zshrc file
In my case, I tried to install Python 3.7.1 and encountered the same error.
This error can occur in two cases:
Incompatible Source Code: Python 3.7.1 was released in 2018, and since then, system libraries on Arch Linux (such as glibc) and compiler versions have evolved. The definition of sinpi in the system headers now conflicts with the static declaration in Python’s Modules/mathmodule.c.
Compiler Environment: Anaconda binaries can conflict with system libraries.
In other cases inspect your /tmp/python-build.*.log file
For the second case, the solution is straightforward: simply comment out conda init in your shell configuration file (e.g., .zshrc or .bashrc), then start a new terminal and ensure the Anaconda paths are removed from your $PATH.
For the first case, the solution is more complicated. I resolved the issue by installing a newer patch version (such as 3.7.17) rather than fixing the installation of 3.7.1. However, I heard from ChatGPT that you can patch the source code to avoid the conflict like this:
pyenv install --patch 3.7.1 <<'EOF'
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@
- sinpi(double x)
+ _py_sinpi(double x)
EOF
I haven’t tested this patch, so I don’t recommend it.