pythonmacosyolo

Python script failing to run on Mac


I have a Python script on my system with simple code named main.py; however, executing this file throws a lot of errors that I do not understand.

The code in main.py is as follows:

from ultralytics import YOLO
#Load Model
model = YOLO("yolo8n.yaml") #Build New Model

#Use model
results = model.train(data="config.yaml", epochs=2) #train the model 

Errors are in the image attached:

Traceback (most recent call last):
  File "main.py", line 1, in <module>
    from ultralytics import YOLO
  File "/opt/miniconda3/lib/python3.8/site-packages/ultralytics/__init__.py", line 5, in <module>
    from ultralytics.models import RTDETR, SAM, YOLO
  File "/opt/miniconda3/lib/python3.8/site-packages/ultralytics/models/__init__.py", line 3, in <module>
    from .rtdetr import RTDETR
  File "/opt/miniconda3/lib/python3.8/site-packages/ultralytics/models/rtdetr/__init__.py", line 3, in <module>
    from .model import RTDETR
  File "/opt/miniconda3/lib/python3.8/site-packages/ultralytics/models/rtdetr/model.py", line 10, in <module>
    from ultralytics.engine.model import Model
  File "/opt/miniconda3/lib/python3.8/site-packages/ultralytics/engine/model.py", line 8, in <module>
    from ultralytics.cfg import TASK2DATA, get_cfg, get_save_dir
  File "/opt/miniconda3/lib/python3.8/site-packages/ultralytics/cfg/__init__.py", line 10, in <module>
    from ultralytics.utils import (ASSETS, DEFAULT_CFG, DEFAULT_CFG_DICT, DEFAULT_CFG_PATH, LOGGER, RANK, ROOT, RUNS_DIR,
  File "/opt/miniconda3/lib/python3.8/site-packages/ultralytics/utils/__init__.py", line 18, in <module>
    import cv2
  File "/opt/miniconda3/lib/python3.8/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/opt/miniconda3/lib/python3.8/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/opt/miniconda3/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: dlopen(/opt/miniconda3/lib/python3.8/site-packages/cv2/python-3.8/cv2.cpython-38-darwin.so, 0x0002): Library not loaded: @rpath/libtiff.5.dylib
  Referenced from: <80BA7539-042B-39DF-A17F-478DE81ACD44> /opt/miniconda3/lib/libopencv_imgcodecs.4.6.0.dylib
  Reason: tried: '/private/var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_f6tvh9615u/croot/opencv-suite_1691620375715/work/build/lib/libtiff.5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/private/var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_f6tvh9615u/croot/opencv-suite_1691620375715/work/build/lib/libtiff.5.dylib' (no such file), '/opt/miniconda3/lib/libtiff.5.dylib' (no such file), '/private/var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_f6tvh9615u/croot/opencv-suite_1691620375715/work/build/lib/libtiff.5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/private/var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_f6tvh9615u/croot/opencv-suite_1691620375715/work/build/lib/libtiff.5.dylib' (no such file), '/opt/miniconda3/lib/libtiff.5.dylib' (no such file), '/private/var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_f6tvh9615u/croot/opencv-suite_1691620375715/work/build/lib/libtiff.5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/private/var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_f6tvh9615u/croot/opencv-suite_1691620375715/work/build/lib/libtiff.5.dylib' (no such file), '/opt/miniconda3/lib/python3.8/site-packages/cv2/python-3.8/../../../../libtiff.5.dylib' (no such file), '/private/var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_f6tvh9615u/croot/opencv-suite_1691620375715/work/build/lib/libtiff.5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/private/var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_f6tvh9615u/croot/opencv-suite_1691620375715/work/build/lib/libtiff.5.dylib' (no such file), '/opt/miniconda3/lib/python3.8/site-packages/cv2/python-3.8/../../../../libtiff.5.dylib' (no such file), '/opt/miniconda3/lib/libtiff.5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/miniconda3/lib/libtiff.5.dylib' (no such file), '/opt/miniconda3/bin/../lib/libtiff.5.dylib' (no such file), '/opt/miniconda3/lib/libtiff.5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/miniconda3/lib/libtiff.5.dylib' (no such file), '/opt/miniconda3/bin/../lib/libtiff.5.dylib' (no such file), '/usr/local/lib/libtiff.5.dylib' (no such file), '/usr/lib/libtiff.5.dylib' (no such file, not in dyld cache)

Image

I tried removing Python and installing it again with no luck.

I have never seen anything like this before,


Solution

  • It's looking for the tiff library that is supposed to be in /opt/miniconda3/lib/libtiff.5.dylib. That miniconda3 installation (of cv2 in particular) needs to be replaced in order for your particular cv2 analysis to run.