Exciting news! TCMS official website is live! Offering full-stack software services including enterprise-level custom R&D, App and mini-program development, multi-system integration, AI, blockchain, and embedded development, empowering digital-intelligent transformation across industries. Visit dev.tekin.cn to discuss cooperation!
This article documents a complete troubleshooting process for a failed Python 3.13 installation via pyenv on macOS, caused by incompatibility issues from globally enabling LLVM clang-21. It presents an elegant, non-destructive solution: keep the latest Clang as the default compiler and temporarily switch back to the system Clang only when compiling Python. This approach balances daily development

When installing Python 3.13 with pyenv, a classic error suddenly occurred: configure: error: C compiler cannot create executables. A previously functional development environment failed to compile Python overnight. Troubleshooting identified the root cause: globally enabled clang-21 conflicts with Python's compilation environment.
This article outlines an elegant solution that keeps clang-21 as the default and switches to the system Clang on demand—it requires no changes to your daily development workflow and resolves pyenv compilation issues with a single command.
Executing the command pyenv install 3.13 results in an immediate build failure with the following error:
BUILD FAILED (OS X 12.7.4 using python-build 2.6.19-7-g48cb1b8a)
...
checking for gcc... /opt/local/libexec/llvm-21/bin/clang
checking whether the C compiler works... no
configure: error: C compiler cannot create executables
After installing LLVM 21, compiler environment variables were configured globally. This forces pyenv to use the incompatible clang-21 (instead of the system's native Clang) when compiling Python, leading to compilation failure.
The Clang path below is for installations via sudo port install clang-21—adjust the path to match your local environment.
# Globally enable clang-21 by default
export PATH="/opt/local/libexec/llvm-21/bin:$PATH"
export LDFLAGS="-L/opt/local/lib -L/opt/local/libexec/llvm-21/lib ${LDFLAGS}"
export CPPFLAGS="-I/opt/local/include -I/opt/local/libexec/llvm-21/include ${CPPFLAGS}"
export CC="/opt/local/libexec/llvm-21/bin/clang"
export CXX="/opt/local/libexec/llvm-21/bin/clang++"
# Alias to temporarily switch back to system Clang
# Use for Python installation (e.g., pyenv install xxx)
alias use-system-clang='
export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
echo "✅ Switched to system Clang temporarily (clang-21 restores on new terminal)"
'
# Quick command for pyenv install (uses system Clang by default)
alias pyenv-install='
use-system-clang && \
pyenv install $1 && \
echo "✅ Python $1 installed successfully"
'
Apply the configuration changes:
source ~/.zshrc # For Bash: source ~/.bash_profile
use-system-clang && pyenv install 3.13.11 (or the shortcut pyenv-install 3.13.11)# Set Python 3.13.11 as the global default
pyenv global 3.13.11
# Verify the installation
python --version # Should output: Python 3.13.11
C compiler cannot create executables, first check the active compiler with echo $CC to confirm if a non-system compiler is in useThe core of this solution is minimally invasive modification: it keeps your preferred clang-21 environment as the default and only switches compilers temporarily when installing Python. This resolves the compilation conflict without any changes to your daily development workflow, making it the optimal solution for balancing custom compiler usage with seamless pyenv functionality.
Tags: #pyenv #PythonInstallation #ClangConflict #macOSDevelopment #EnvironmentConfiguration #Troubleshooting #MacPorts