Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

python3 is unavailable when cross compiling OpenCV

Open
#1,128 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
android, cmake, python

Research direction

Start with the supplied CMake invocation, especially the PYTHON3_* settings, and inspect the Android toolchain configuration at /home/ad/Android/Sdk/ndk/27.2.12479018/build/cmake/android.toolchain.cmake. Compare the host and target Python paths during CMake configuration; done means the Python 3 options are populated and the target Python library configuration completes successfully.

Written by the indexing model from the issue text.

Description

  1. Environment and Target

Build environment: Ubuntu 22.04
Target environment: aarch64-Linux-Android
OpenCV:4.10
I have cross compiled Python 3.11 and it can run on Android arm-v8a. I want to cross compile OpenCV to generate a Python library that supports the target environment.

  1. Building
    This is my cmake script:
export PYTHON_HOST=/home/ad/host-dev/x86_python311
export PYTHON_TARGET=/home/ad/dev-lib/python311
cmake \
 -DCMAKE_TOOLCHAIN_FILE=/home/ad/Android/Sdk/ndk/27.2.12479018/build/cmake/android.toolchain.cmake \
 -DCMAKE_BUILD_TYPE=Release \
 -DANDROID_ABI:STRING=arm64-v8a \
 -DANDROID_PLATFORM:STRING=android-30 \
 -DCMAKE_INSTALL_PREFIX:PATH=/home/ad/dev-lib/opencv/myinstall \
 -DBUILD_SHARED_LIBS:BOOL=ON \
 -DANDROID_STL=c++_shared \
 -DBUILD_opencv_python2:BOOL=OFF \
 -DBUILD_opencv_python3:BOOL=ON \
 -DPYTHON3_EXECUTABLE:FILEPATH=${PYTHON_HOST}/bin/python3.11 \
 -DPYTHON3_INCLUDE_DIR:PATH=${PYTHON_TARGET}/include/python3.11 \
 -DPYTHON3_LIBRARY:FILEPATH=${PYTHON_TARGET}/lib/libpython3.11.so.1.0 \
 -DOPENCV_PYTHON3_INSTALL_PATH:PATH=${PYTHON_TARGET}/lib/python3.11/site-packages \
 -DPYTHON3_PACKAGES_PATH:PATH=${PYTHON_TARGET}/lib/python3.11/site-packages \
 -DPYTHON3_NUMPY_INCLUDE_DIRS:PATH=${PYTHON_TARGET}/lib/python3.11/site-packages/numpy/_core/include \
 -S ./ -B ./mybuild

After executing the cmake command,python3 is unavailable, the options related to Python 3 are empty, as shown in the following figure.

Image

Image

This is my env:

export ANDROID_NDK_HOME=/home/ad/Android/Sdk/ndk/27.2.12479018
export ANDROID_HOME=/home/ad/Android/Sdk
export ANDROID_SDK_PLANTFORM_TOOLS=/home/ad/Android/Sdk/platform-tools
export MESON_PATH="/home/ad/.local/bin"
export CMAKE_ANDROID_NDK="/home/ad/Android/Sdk/cmake/4.0.2" 
export PYTHON3_BIN=/home/ad/host-dev/x86_python311
export LD_LIBRARY_PATH=/home/ad/dev-lib/python311/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/ad/host-dev/x86_python311/lib/:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/ad/host-dev/x86_python311/lib/python3.11/site-packages/numpy/_core:$LD_LIBRARY_PATH
export PATH=$ANDROID_NDK_HOME:$ANDROID_HOME:$ANDROID_SDK_PLANTFORM_TOOLS:$CMAKE_ANDROID_NDK:$PYTHON3_BIN:$PATH
  1. Question
    (1)Is there a fight for the setting of PYTHON3_deECUTABLE, PYTHON3-INCLUDE-DIR, and PYTHON3_LIBRRY? Which parameter is the Python of the host machine? Which is the Python parameter for the target platform?
    (2)How should I modify cmake or environment variable parameters?
Dominant language
Python
Stars
5.4k
Forks
1k
Avg merge
22h 17m
Merged PRs (30d)
3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from opencv/opencv-python

All issues in opencv/opencv-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.