Skip to content

Maturin does not work in Python 3.13 on Android unless I edit Maturin #2945

Closed as not planned

Description

@robertkirkman

Bug Description

using pip install meshage does not work in Python 3.13 on Android because this error occurs:

💥 maturin failed
Caused by: Failed to get information from the python interpreter at /data/data/com.termux/files/usr/bin/python3.13
Caused by: platform.system() in python, android, and the rust target, Target { os: Linux, arch: X86, env: Android, triple: "i686-linux-android", cross_compiling: false, rustc_version: VersionMeta { semver: Version { major: 1, minor: 92, patch: 0 }, commit_hash: Some("ded5c06cf21d2b93bffd5d884aa6e96934ee4234"), commit_date: Some("2025-12-08"), build_date: None, channel: Stable, host: "i686-linux-android", short_version_string: "rustc 1.92.0 (ded5c06cf 2025-12-08) (built from a source tarball)", llvm_version: Some(LlvmVersion { major: 21, minor: 1 }) }, user_specified: false }, don't match ಠ_ಠ
Error running maturin: Command '['maturin', 'pep517', 'write-dist-info', '--metadata-directory', '/data/data/com.termux/files/usr/tmp/pip-modern-metadata-a3waxdbn', '--interpreter', '/data/data/com.termux/files/usr/bin/python3.13']' returned non-zero exit status 1.
Checking for Rust toolchain....
Running `maturin pep517 write-dist-info --metadata-directory /data/data/com.termux/files/usr/tmp/pip-modern-metadata-a3waxdbn --interpreter /data/data/com.termux/files/usr/bin/python3.13`

However, when I edit Maturin and use several other commands like this, meshage installs successfully in Python 3.13 on Android.

git clone https://github.com/PyO3/maturin.git
cd maturin
git apply -v << 'EOF'
--- a/src/target/mod.rs
+++ b/src/target/mod.rs
@@ -456,6 +456,9 @@ impl Target {
 
     /// Returns the name python uses in `sys.platform` for this os
     pub fn get_python_os(&self) -> &str {
+        if (self.is_bionic_libc()) {
+            return "android";
+        }
         match self.os {
             Os::Windows => "windows",
             Os::Linux => "linux",
@@ -682,6 +685,15 @@ impl Target {
         )
     }
 
+    /// Returns true if the current platform's target env is Android
+    #[inline]
+    pub fn is_bionic_libc(&self) -> bool {
+        matches!(
+            self.env,
+            Environment::Android
+        )
+    }
+
     /// Is cross compiling for this target
     #[inline]
     pub fn cross_compiling(&self) -> bool {
EOF
pip install .
pip install cffi
export ANDROID_API_LEVEL=24
pip install --upgrade --force-reinstall setuptools
pip cache purge
pip install --no-build-isolation meshage

Your maturin version (maturin --version)

maturin 1.11.5

Your Python version (python -V)

Python 3.13.11

Your pip version (pip -V)

pip 25.3 from /data/data/com.termux/files/usr/lib/python3.13/site-packages/pip (python 3.13)

What bindings you're using

cffi

Does cargo build work?

  • Yes, it works

If on windows, have you checked that you aren't accidentally using unix path (those with the forward slash /)?

  • Yes

Steps to Reproduce

  1. Install Android
  2. Install Termux App for Android
  3. Fully update Termux App (pkg upgrade)
  4. Install Python 3.13 for Termux App
  5. Install Rust for Termux App (pkg install rust)
  6. set the Maturin Android API level to the current minimum API level of Termux App (export ANDROID_API_LEVEL=24)
  7. Try to install a PyPi package that depends on Maturin (pip install meshage)

Activity

  1. robertkirkman commented on Jan 22, 2026

    @robertkirkman
    Author

    I should note that the patch I sent is not backwards compatible with Maturin in Python 3.12 on Android, so I'm not sure what the best way to fix Maturin for both Python 3.12 on Android and Python 3.13 on Android at the same time would be.

    One idea is that I did notice there appears to be a hardcoded loosening/exception in this check for the case of Windows; I don't know if Android could acceptably be granted an exception in the check this way or not.

    && !(target.get_python_os() == "cygwin"
    && message.system.to_lowercase().starts_with("cygwin"))

  2. messense commented on Feb 8, 2026

    @messense
    Member

    I think we should only aim for Android support for Python 3.14+ given that CPython only added official Android support since 3.14.

  3. mhsmith commented on Feb 8, 2026

    @mhsmith

    That's not correct, Python added official Android support in 3.13 (https://peps.python.org/pep-0738/).

    We didn't start making official binary releases until 3.14, but that isn't an indication of support, since there are no offical binary releases for Linux either.

  4. thunder-coding commented on Feb 12, 2026

    @thunder-coding
    Contributor

    Just gave a better look at maturin, it should be possible to do a proper support for Android while keeping backward compatibility with Python 3.12 and earlier. I'll be opening a PR soon after getting it built locally and testing it. Will be CCing both of you

  5. DresOperatingSystems commented on Apr 9, 2026

    @DresOperatingSystems

    Temporary Fix — Downgrade to Python 3.11 Until 3.13 Is Stable in Termux

    I ran into the same issue and got maturin working again by switching to Python 3.11. Here are the steps that worked for me.


    Steps

    1. Install Python 3.11

    apt install python3.11

    This installs Python 3.11 alongside your existing 3.13 install, nothing is removed or broken.


    2. Remove the broken getrandom crate cache

    rm -rf ~/.cargo/registry/cache/index.crates.io-*/getrandom-0.3.4.crate
    rm -rf ~/.cargo/registry/src/index.crates.io-*/getrandom-0.3.4

    Clears a cached Rust crate that has a compatibility issue in Termux. Forcing it out makes Cargo fall back to a working version on the next build.


    3. Install maturin under Python 3.11

    pip3.11 install "maturin==1.7.4"

    Installs a version of maturin that is known to work with Python 3.11, avoiding any 3.13 specific binding issues.


    4. Symlink Python 3.11 as the default python and python3

    ln -sf $(which python3.11) ~/bin/python
    ln -sf $(which python3.11) ~/bin/python3

    Makes python and python3 point to 3.11 without touching or removing your 3.13 install, fully reversible.


    5. Prioritise ~/bin in your PATH and make it permanent

    export PATH="$HOME/bin:$PATH"
    echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
    source ~/.bashrc

    The export line alone only lasts for the current session. Writing it to .bashrc makes it persist across terminal restarts so your symlinks always take priority over system binaries.

    If you use zsh, replace ~/.bashrc with ~/.zshrc.


    Note: This is a temporary workaround until Python 3.13 is fully stable within Termux. Python 3.13 is not removed, it is just deprioritised. If anything in your environment explicitly calls python3.13, it will still use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions