I ran pip install numpy pillow in Termux, watched the compiler grind for a while, and got a screen of red text ending in Failed building wheel for numpy. Then I scrolled up and the Pillow build had died too. I’d asked pip for two of the most common packages in Python, and it had decided to compile both on a phone.
That’s the actual problem. pip isn’t broken, and neither are the packages. It’s compiling because it found nothing to download, and a phone is the worst machine to do that on.
Why pip falls back to compiling #
NumPy and Pillow publish ready-made Linux wheels for aarch64, so the old explanation that PyPI only has x86 binaries is wrong. Those wheels are built against glibc, and Termux doesn’t use glibc. Android’s C library is Bionic, and Bionic can’t satisfy a glibc constraint. The practical result, according to a thread on the Python forums about distributing wheels for Termux, is that manylinux wheels don’t install in Termux, and pip falls back to the source distribution. Your Python also identifies itself to pip as a plain linux-aarch64 platform, which is why the tags don’t line up.
Once pip falls back to source, both packages need real build setups. NumPy wants C and C++ compilers, the Python headers, and BLAS and LAPACK libraries, with OpenBLAS as the default. It also needs pkg-config for dependency detection. Notably, it does not need Fortran: a Fortran compiler is only needed for the f2py tests. Pillow needs the C libraries for each image format it supports, starting with libjpeg and zlib. When any of those is missing, the build dies, usually after a long compile.
Confirm it before you wait on a build #
You can skip the long failure. Tell pip it isn’t allowed to compile:
pip install --only-binary=:all: numpyIf no compatible wheel exists for your platform, pip stops immediately with a “no matching distribution” style error instead of burning minutes on a compile that was never going to work. For more detail, pip debug --verbose lists every wheel tag your pip will accept. On Termux, you won’t find the manylinux ones.
The fix: let Termux do the compiling #
Termux’s package repository ships NumPy and Pillow already compiled for this platform, and installing them takes seconds:
pkg update && pkg upgrade
pkg install python python-numpy python-pillow
python -c "import numpy, PIL; print(numpy.__version__, PIL.__version__)"If pkg can’t find one of those names, check with pkg search pillow or pkg search numpy first, since repository names change. When the one-liner prints two version numbers, you’re done. pip will see these packages too, because they land in the same site-packages as everything pip installs, so a later pip install of something that depends on NumPy won’t try to fetch it again.
Working inside a virtual environment #
A plain python -m venv creates an empty environment that can’t see anything installed through pkg, so people end up back at a source build. The fix is one flag. The usual advice for Termux is to create the environment with python -m venv --system-site-packages, which makes python-numpy available inside it.
python -m venv --system-site-packages .venv
source .venv/bin/activate
pip install -r requirements.txtpip installs everything else into the environment and treats the pkg packages as already satisfied.
Check which copy Python is actually importing #
When something behaves oddly after mixing pkg and pip, stop guessing and ask Python where it found the package:
python -c "import numpy; print(numpy.__version__, numpy.__file__)"
python -c "import PIL; print(PIL.__version__, PIL.__file__)"
pip show numpy__file__ is the copy that actually loaded, and pip show prints a Location line for the one pip knows about. If they disagree, or the version isn’t what you expected, you have two copies fighting, and whichever sits earlier on sys.path wins. Clear it up by removing pip’s copy and letting Termux put its own back:
pip uninstall numpy
pkg reinstall python-numpySame idea for Pillow: pip uninstall pillow, then pkg reinstall python-pillow. And pip list takes a second to run, so run it before you blame a package.
When another package needs NumPy to build #
This one catches people who did everything right. You install python-numpy with pkg, then run pip install pandas, and it still tries to build NumPy. Reports from Termux users show exactly that: pandas failing during “Installing build dependencies” while the log fills up with NumPy build output. The reason is build isolation. By default, pip builds each package in a throwaway environment and installs that package’s build requirements into it, ignoring your installed NumPy. If those requirements include NumPy, pip tries to compile a fresh copy there.
You can turn isolation off with --no-build-isolation, which makes pip use whatever is already installed. NumPy’s own docs treat it as standard for source builds, stressing that you should always pass it so the build doesn’t pick up a NumPy wheel from PyPI. The catch is that you become responsible for the build requirements. Read the [build-system] section of the package’s pyproject.toml and install those first. Before any of that, run pkg search python- and see whether Termux already ships the package you want.
If you have to build from source #
Sometimes pkg doesn’t carry the exact version you need. Then you’re compiling, and the two packages behave differently.
Pillow is the easier one. Its own docs include an Android section for Termux: pkg install -y python ndk-sysroot clang make libjpeg-turbo. Add the libraries for the other formats you care about, such as libpng, freetype and zlib. Note that ndk-sysroot is on that list and a plain clang install doesn’t pull it in. You don’t need a separate python-dev package. Pillow’s Termux instructions don’t list one, and the Python headers come with python.
NumPy is the slog:
pkg install python clang make cmake ninja pkg-config libopenblas ndk-sysroot
pip install --upgrade pip setuptools wheelThen install the build requirements from NumPy’s pyproject.toml, and build with isolation off:
pip install --no-build-isolation numpyInstall cmake and ninja with pkg, not from PyPI. People who’ve tried building those two PyPI packages on Termux report that the source build is broken on that platform. With isolation disabled, pip uses the ones pkg provided.
A note on BLAS, because it’s where the old advice goes stale. Exporting BLAS=openblas and LAPACK=openblas belongs to the old setup.py-era build. Current NumPy builds with Meson and locates BLAS through pkg-config, as its docs describe: the location is given through a pkg-config .pc file. If the build can’t find OpenBLAS on its own, NumPy’s docs describe pointing it there with -Csetup-args=-Dblas=openblas -Csetup-args=-Dlapack=openblas. Older Termux guides also mention setting MATHLIB=m for NumPy builds, so expect to see that if you go digging through old threads.
The practical warnings are about time and survival. Compiling NumPy on a phone is a long job, and Android can kill Termux in the middle of it. If you see signal 9, that’s what happened. Plug in the charger, run termux-wake-lock so the process isn’t suspended, and be ready to restart the build.
Keeping it from breaking again #
Don’t install the same package both ways. A pkg NumPy and a pip NumPy in the same environment is how you end up with a version that imports and a version that doesn’t match the rest of your stack. Pick pkg for anything with heavy native code, which covers NumPy, SciPy-adjacent packages and Pillow, and keep pip for pure-Python libraries.
Know where pip’s packages live. The site-packages path includes the Python minor version, as in .../usr/lib/python3.11/site-packages, as it does in Termux error logs. When Termux upgrades Python from one minor version to the next, packages you installed with pip stay behind in the old directory and have to be reinstalled. The pkg ones get rebuilt for the new version by Termux. That’s the real reason to run pkg upgrade regularly, and the reason a working setup can break right after a Python upgrade.
pip didn’t fail. It did what it was told, on a platform where the answer was always going to be “compile it yourself.” pkg already did that part for you.