chaquo / chaquopy

Chaquopy: the Python SDK for Android
https://chaquo.com/chaquopy/
MIT License
849 stars 133 forks source link

As an error occurred when running the program after installing "ultralytics==8.0.16", after changing it to "ultralytics==8.0.06", another error occurred when running. #1286

Closed caiyongrt closed 2 weeks ago

caiyongrt commented 2 weeks ago

1.The environment used is chaquopy 16.0.0, and the Python version is 3.12.7. 2.The code in the build.gradle of the app is:

chaquopy {
defaultConfig {
pip {
install "ultralytics==8.0.06"
install "seaborn==0.12.2"
}
}
}

3.python代码为:

import os
os.environ['GIT_PYTHON_REFRESH'] = 'quiet'

from pathlib import Path
# Return the appropriate config directory for each operating system
sub_dir="Ultralytics"
path = Path.home() / ".config" / sub_dir
# Create the subdirectory if it does not exist
path.mkdir(parents=True, exist_ok=True)
USER_CONFIG_DIR = path  # Ultralytics settings dir
print('import from pathlib import Path成功')
print(USER_CONFIG_DIR)

from ultralytics import YOLO
print('import ultralytics successfully')

import cv2
print('import cv2 successfully')

def test(videoPath):

    print('The test function is called successfully')
    return video_path

4.The above code cannot import the ultralytics library. The print statement 'import ultralytics successfully' is not printed.。 5.The error prompt for program running is:【Caused by: com.chaquo.python.PyException: FileNotFoundError: [Errno 2] No such file or directory: 'git'】 6.The complete error prompt is as follows:

FATAL EXCEPTION: main Process: cycom.example.cy_test1, PID: 6842
java.lang.RuntimeException: Unable to start activity ComponentInfo{cycom.example.cy_test1/cycom.example.cy_test1.MainActivity}: com.chaquo.python.PyException: FileNotFoundError: [Errno 2] No such file or directory: 'git'
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3668)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3823)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2279)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:230)
    at android.app.ActivityThread.main(ActivityThread.java:7987)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:526)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)
Caused by: com.chaquo.python.PyException: FileNotFoundError: [Errno 2] No such file or directory: 'git'
    at <python>.subprocess._execute_child(subprocess.py:1720)
    at <python>.subprocess.__init__(subprocess.py:858)
    at <python>.subprocess.run(subprocess.py:493)
    at <python>.ultralytics.yolo.utils.get_git_root_dir(__init__.py:189)
    at <python>.ultralytics.yolo.utils.get_settings(__init__.py:365)
    at <python>.ultralytics.yolo.utils.<module>(__init__.py:405)
    at <python>.ultralytics.yolo.configs.hydra_patch.<module>(hydra_patch.py:12)
    at <python>.ultralytics.yolo.configs.<module>(__init__.py:8)
    at <python>.ultralytics.yolo.v8.<module>(__init__.py:3)
    at <python>.ultralytics.yolo.<module>(__init__.py:3)
    at <python>.ultralytics.hub.utils.<module>(utils.py:10)
    at <python>.ultralytics.hub.auth.<module>(auth.py:5)
    at <python>.ultralytics.hub.<module>(__init__.py:10)
    at <python>.ultralytics.<module>(__init__.py:5)
    at <python>.java.chaquopy.import_override(import.pxi:26)
    at <python>.cy.<module>(cy.py:14)
    at <python>.importlib._bootstrap._call_with_frames_removed(<frozen importlib._bootstrap>:219)
    at <python>.importlib._bootstrap_external.exec_module(<frozen importlib._bootstrap_external>:843)
    at <python>.java.android.importer.exec_module(importer.py:626)
    at <python>.java.android.importer.exec_module(importer.py:714)
    at <python>.importlib._bootstrap._load_unlocked(<frozen importlib._bootstrap>:671)
    at <python>.importlib._bootstrap._find_and_load_unlocked(<frozen importlib._bootstrap>:975)
    at <python>.importlib._bootstrap._find_and_load(<frozen importlib._bootstrap>:991)
    at <python>.importlib._bootstrap._gcd_import(<frozen importlib._bootstrap>:1014)
    at <python>.importlib.import_module(__init__.py:127)
    at <python>.chaquopy_java.Java_com_chaquo_python_Python_getModuleNative(chaquopy_java.pyx:127)
    at com.chaquo.python.Python.getModuleNative(Native Method)
    at com.chaquo.python.Python.getModule(Python.java:84)
    at cycom.example.cy_test1.MainActivity.callPythonCode(MainActivity.java:211)
    at cycom.example.cy_test1.MainActivity.onCreate(MainActivity.java:67)
    at android.app.Activity.performCreate(Activity.java:7894)
    at android.app.Activity.performCreate(Activity.java:7883)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1353)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3643)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3823) 
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) 
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2279) 
    at android.os.Handler.dispatchMessage(Handler.java:107) 
    at android.os.Looper.loop(Looper.java:230) 
    at android.app.ActivityThread.main(ActivityThread.java:7987) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:526) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034) 
mhsmith commented 2 weeks ago

This is probably a variation of the git issue in #1106, but it looks like this version of ultralytics doesn't have any obvious workaround for git being missing. And since you've already created #1285 for ultralytics 8.0.16, let's focus on that for now.