pytorch Python的“No module named 'ultralytics'”错误

yi0zb3m4  于 2023-11-19  发布在  Python
关注(0)|答案(1)|浏览(558)

我用yolov5和opencv写了一段简单的代码,然后用pyinstaller部署到exe文件中。但是,这个部署的文件在执行时立即退出。当我直接从终端运行这个文件时,我遇到了一个错误,说明**“No module named 'ultralytics'”**。
下面是我的代码。

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()

字符串

wbgh16ku

wbgh16ku1#

我在使用python3.9时遇到了和你一样的问题,并通过以下方式解决了它,在virtualenv激活时:

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

字符串

相关问题