Python's "No module named 'ultralytics'" Error

563 views Asked by At

I've written a simple code using yolov5 and opencv. I then deployed it into an exe file using pyinstaller. However, this deployed file exits immediately upon execution. When I ran this file directly from the terminal, I encountered an error stating "No module named 'ultralytics'".

Below is my code.

import cv2
import torch
from PIL import Image
import os

# model load
model = torch.hub.load('ultralytics/yolov5', 'custom', path='model.pt')

# opencv cam
cap = cv2.VideoCapture(0)

while True:
    ret, frame = cap.read()

    if not ret:
        break

    pil_image = Image.fromarray(frame)
    results = model(pil_image)

    output_frame = results.render()[0]  
    cv2.imshow('Object Detection', output_frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()
1

There are 1 answers

0
matleg On

I ran into the same problem as you with python3.9 and solved it the following way, in the virtualenv activated:

# pip install ultralytics --> was not working
sudo apt-get install python3.9-distutils  # install linux package distribution-wide
pip install ultralytics  # working now!