You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Buildozer打包Kivy时出现Python2.7调用问题咨询

Why is Buildozer using Python 2.7 even after following the Python 3 setup process?

Let's break down your problem step by step:

First, why is Python 2.7 being called?

There are a few common reasons for this discrepancy, even when you intended to use Python 3:

  • Your system's default python command points to Python 2.7. Many Linux distributions (including the Kivy-provided VM) still default to Python 2.7 for the generic python alias. If Buildozer or its helper scripts use python instead of explicitly calling python3, it'll fall back to the system's pre-installed Python 2.7.
  • You might have installed Buildozer using Python 2's pip instead of Python 3's pip3. This links Buildozer's executable to the Python 2 environment, overriding your intention to use Python 3.
  • Your VM's environment variables aren't configured to prioritize Python 3. Without setting python3 as the default alias, tools will default to the system's older Python version.

Is this the root cause of your build failure?

Absolutely. Your buildozer.spec specifies python3crystax as a requirement, which relies entirely on a Python 3 runtime. When the build process uses Python 2.7 to execute scripts designed for Python 3, you'll hit compatibility issues—like syntax errors, missing Python 3-specific modules, or mismatched dependencies. The traceback showing /usr/lib/python2.7/runpy.py confirms the wrong Python version is driving the build, and this is almost certainly why your build fails with sh.ErrorReturnCode_2.

How to fix it

Here's a step-by-step fix to force Buildozer to use Python 3:

  1. Verify your Python versions
    Run these commands in your VM terminal to confirm which versions are active:

    python --version
    python3 --version
    

    You'll likely see Python 2.7 for the first command, and a Python 3.x release for the second.

  2. Reinstall Buildozer using Python 3

    • First, remove any existing Buildozer installations:
      pip uninstall buildozer -y
      pip3 uninstall buildozer -y
      
    • Install Buildozer using Python 3's package manager:
      pip3 install buildozer
      
    • If you installed from source, ensure you use Python 3 to run the setup:
      cd path/to/buildozer-source
      python3 setup.py install
      
  3. Update your buildozer.spec to enforce Python 3
    Add or confirm this line is present in your spec file:

    android.python_version = 3
    

    This explicitly tells Buildozer to target Python 3 for the Android build.

  4. Set Python 3 as your default alias
    Edit your ~/.bashrc file to add:

    alias python=python3
    

    Apply the change immediately:

    source ~/.bashrc
    
  5. Clean and rebuild
    Clear cached build files to eliminate any leftover Python 2.7 artifacts:

    buildozer android clean
    

    Then restart the build process:

    buildozer android debug
    

As an extra check, confirm your android.ndk_path in buildozer.spec points to the correct Crystax NDK location—an incorrect path could cause additional issues, but the Python version mismatch is your primary blocker right now.

内容的提问来源于stack exchange,提问作者jasan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:06:22