I want to execute python code in my Flutter macos app to run a YOLO object detection model.
I am using the https://pub.dev/packages?q=process_run package to execute shell commands.
The package works and will run a python file with a simple print function, but not my object detection file.
I have cloned https://github.com/ultralytics/yolov5 inside of my app.
In my flutter app I have a function:
_runPython() async {
var shell = Shell();
await shell.run('''
python3 yolov5/detect.py
''');
}
When I call _runPython I get the error:
Traceback (most recent call last):
File "yolov5/detect.py", line 39, in <module>
import torch
ModuleNotFoundError: No module named 'torch'
However when I run python3 yolov5/detect.py
in my terminal the code executes just fine.
Looking inside of my python files inside of my app I don’t see any errors, and everything appears to be imported.
Why is my detect.py working via the terminal and not from my Flutter app?