Initial Setup
To begin, you need to build Python correctly:
make distclean
bash configure --prefix=$PREFIX --enable-optimizations
Use Parallel Compilation
It’s useful to run:
make -j$(nproc)
This distributes the load across all 8 of my CPU cores, instead of funneling everything into a single thread.
Missing ar Archiver
If you encounter an error about a missing ar archiver, install the appropriate package:
Fixing Platform-Specific Issues
In the working directory of the CPython repository, there’s a file called pyconfig.h.
Just append the following lines to the end (or, like I did, search for each parameter manually and comment out the corresponding #define):
#undef HAVE_SEM_CLOCKWAIT
#undef HAVE_PTHREAD_GETNAME_NP
#undef HAVE_PTHREAD_SETNAME_NP
// These errors were mostly triggered by Modules/posixmodule.c:
#undef HAVE_STATX
#undef HAVE_FEXECVE
#undef HAVE_GETLOGIN_R
#undef HAVE_GETLOADAVG
#undef HAVE_PWRITEV2
#undef HAVE_PREADV2
#undef HAVE_GETPWENT
This is a Termux-specific issue: the GCC compiler simply lacks these functions 
If you run into problems, inspect the code and look for #if or #ifdef blocks — usually the missing symbol name is mirrored in a HAVE_ macro.
Gotcha: #define ... 0 Doesn’t Work
#define HAVE_PTHREAD_GETNAME_NP 0 // ❌ Doesn't work
#undef HAVE_PTHREAD_GETNAME_NP // ✅ Works
I thought the developers messed up, but in reality, you need to check the comment ending with:
", and to 0 if you don't." — which precedes the #define.
Still, this isn’t always reliable, since different developers interpret it differently.
Running Python from the CPython Repo
To run the freshly built Python:
./python
If you just type python, it will launch Termux’s default version — currently 3.12.9 at the time of writing.
Crude but Working Override (No make install, no PGO, no symlinks)
export PATH="$PWD:$PATH"
python --version
# Output: Python 3.15.0a1+
This works only for the current session and doesn’t support pip.
Testing Notes
During testing, some modules failed. Test 41/43 even crashed the test runner due to Android security restrictions.
Example: testing re
>>> import re
>>> dir(re)
['A', 'ASCII', 'DEBUG', 'DOTALL', 'I', ...]
>>> print(re.findall(r'\d+', 'abc123def456'))
['123', '456']
As you can see, re works fine. The test failure was due to a fork() or similar system call not supported on Android — so we can safely ignore it.
Cleaning Up PGO Tests Before make install
Before running make install, go to:
Lib/test/libregrtest/pgo.py
Delete all tests that fail. In particular, 'test_time' crashes the process entirely.
You can remove all tests, but it’s better to leave the first 7 — they run quickly and pass.
This lets you keep --pgo mode (enabled via --enable-optimizations) while still installing Python properly.
Yes, the build will repeat… and without the -j flag 
But the resulting Python will be well optimized 
Symlinks
ln -sf $PREFIX/bin/python3.15 $PREFIX/bin/python
ln -sf $PREFIX/bin/pip3.15 $PREFIX/bin/pip
Final Check (Outside the CPython Repo)
python --version
pip --version
At the time of writing, I built Python 3.15.0a1 (Works for any version of python, can only change HAVE_*).