No module named Pathlib

Hi,
I keep getting this error when trying to run my code:

Traceback (most recent call last):
  File "yolotest.py", line 5, in <module>
    model = torch.hub.load('/home/jetson/mebrobot/yolov5', 'custom', path='/home/jetson/mebrobot/best.pt', source='local')
  File "/usr/local/lib/python3.8/dist-packages/torch/hub.py", line 339, in load
    model = _load_local(repo_or_dir, model, *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/torch/hub.py", line 368, in _load_local
    model = entry(*args, **kwargs)
  File "/home/jetson/mebrobot/yolov5/hubconf.py", line 135, in custom
    return _create(path, autoshape=autoshape, verbose=_verbose, device=device)
  File "/home/jetson/mebrobot/yolov5/hubconf.py", line 103, in _create
    raise Exception(s) from e
Exception: No module named 'pathlib._local'; 'pathlib' is not a package. Cache may be out of date, try `force_reload=True` or see https://docs.ultralytics.com/yolov5/tutorials/pytorch_hub_model_loading for help.

Here is the code I am trying to run:

import torch
import cv2

model = torch.hub.load('/home/jetson/mebrobot/yolov5', 'custom', path='/home/jetson/mebrobot/best.pt', source='local')

cap = cv2.VideoCapture('/home/jetson/mebrobot/video_test.mp4')

if not cap.isOpened():
    print("Failed to open video.")
    exit()

while True:
    ret, frame = cap.read()
    if not ret:
        print("Video ended.")
        break

    results = model(frame)

    annotated_frame = results.render()[0]

    cv2.imshow('YOLOv5 Detection', annotated_frame)

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

cap.release()
cv2.destroyAllWindows()

I am using Python 3.8.0 on Jetson.
I have installed all the required libraries.

I already tried:

  • Deleting and reinstalling pathlib.
  • Creating a virtual environment and installing everything again.

But I still get the same error.
I would appreciate any help. Thanks in advance!