Skip to content

Error running app that imports cv2 #4850

@Greg-Griffith

Description

@Greg-Griffith

Duplicate Check

Describe the bug

What I am experiencing seems to be a duplicate of #2714 except it happens on android and linux for me after i build an APK or linux bundle. The app compiles fine and gives the missing config.py error when it is run.

it does not happen when the app is started with flet run

I did not test on other platforms / operating systems

Code sample

Code
import os
import sys

import flet as ft
import cv2


def app_main(page: ft.Page):
    detector = cv2.QRCodeDetector()
    page.add(ft.Text("Hello, world!"))


def main():
    """ Main entry point into this script """
    # enforce python3.10+ requirement
    if sys.version_info[0] < 3:
        raise 'Use Python 3.10+'
    if sys.version_info[1] < 10:
        raise 'Use Python 3.10+'

    #import logging
    #logging.basicConfig(level=logging.DEBUG)
    ft.app(target=app_main, assets_dir="assets")

if __name__ == '__main__':
    main()
[project]
name = "qrscanner"
version = "0.1.0"
description = ""
readme = "README.md"
requires-python = ">=3.10"
authors = [
    { name = "", email = "" }
]
classifiers = [
  # How mature is this project? Common values are
  #   3 - Alpha
  #   4 - Beta
  #   5 - Production/Stable
  "Development Status :: 4 - Beta",
]
dependencies = [
  "pip",
  "flet==0.26.0",
  "charset-normalizer==3.3.2",
  "pathvalidate==2.3.2",
  "PySocks==1.7.1",
  "python-dateutil==2.8.2",
  "qrcode==7.4.2",
  "requests==2.31.0",
  "six==1.16.0",
  "wheel==0.42.0",
  "pillow==10.4.0",
  "opencv-python==4.10.0.84",
]

[flutter]
dependencies = ["flet_video", "flet_audio"]


[tool.flet]
org = ""
product = "Qrscanner"
company = ""
copyright = ""
permissions = ["camera"] # camera for QR codes
output = "build"


[tool.flet.compile]
app = true # compile app's .py files.
packages = true # compile installed packages' .py files.
cleanup = true # remove unnecessary files upon successful compilation.


[tool.flet.app]
path = "qrscanner"


[tool.flet.splash]
color = "#FFFF00" # --splash-color
dark_color = "#8B8000" # --splash-dark-color
web = false # --no-web-splash
ios = false # --no-ios-splash
android = false # --no-android-splash


[tool.flet.android]
split_per_abi = false


[tool.flet.android.permission] # --android-permissions
"android.permission.CAMERA" = true
"android.permission.ACCESS_FINE_LOCATION" = false
"android.permission.ACCESS_COARSE_LOCATION" = false
"android.permission.ACCESS_BACKGROUND_LOCATION" = false
"android.permission.RECORD_AUDIO" = false
"android.permission.WRITE_EXTERNAL_STORAGE" = false
"android.permission.READ_EXTERNAL_STORAGE" = false


[tool.flet.android.feature] # --android-features
"android.hardware.camera" = true
"android.hardware.location.network" = false
"android.hardware.location.gps" = false

To reproduce

  1. mkdir opencv-test
  2. cd opencv-test
  3. add the pyproject.toml file and the main.py file from the Code Sample section of this issue to the opencv-test
  4. run flet build apk -v --flutter-build-args=--debug --clear-cache
  5. install the created app on a phone somehow, i used adb via adb install ./build/apk/app-debug.apk
  6. run the app and get the traceback of the opencv config error

or alternatively to reproduce the same issue on ubuntu
4. run flet build linux -v --flutter-build-args=--debug --clear-cache
5. run the app and get the traceback of the opencv config error

Expected behavior

I expected the app to run, not show an opencv config error

Screenshots / Videos

Captures

Operating System

Linux

Operating system details

Ubuntu24 compiling an APK for android and a linux bundle. other OS/platforms untested

Flet version

Version: 0.26.0

Regression

I'm not sure / I don't know

Suggestions

No response

Logs

Logs
Traceback (most recent call last):
  File "<string>", line 95, in <module>
  File "<frozen runpy>", line 229, in run_module
  File "<frozen runpy>", line 88, in _run_code
  File "/tmp/serious_python_tempFWCHUR/main.py", line 5, in <module>
  File "/home/<user>/<folder0>/<folder1>/<folder2>/build/site-packages/arm64-v8a/cv2/__init__.py", line 181, in <module>
  File "/home/<user>/<folder0>/<folder1>/<folder2>/build/site-packages/arm64-v8a/cv2/__init__.py", line 111, in bootstrap
  File "/home/<user>/<folder0>/<folder1>/<folder2>/build/site-packages/arm64-v8a/cv2/__init__.py", line 109, in load_first_config
ImportError: OpenCV loader: missing configuration file: ['config.py']. Check OpenCV installation.

Additional details

I am undecided if this is considered a regression. opencv-python used to work for me in flet 0.24.x using the python-for-android packages and the old build system. I have never had it working with this new build system.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions