Home > database >  Unable to find module/folder despite being in the same directory
Unable to find module/folder despite being in the same directory

Time:02-17

I am attempting to run a script which calls another python file (copied along with its entire github repo), but I am getting a ModuleNotFoundError: This is despite putting the files into the correct directories.

How I run it

  1. Activate my python3.9 virtual environment
  2. (newpy39) aevas@aevas-Precision-7560:~/Desktop/Dashboard_2021_12$ python3 dashboard.py where aevas is my username, and ~/Desktop/Dashboard_2021_12 is the folder

No additional arguments required to run it.

Imports for dashboard.py

import sys
sys.path.insert(1, 'targetTrack')

# Qt imports
from PyQt5.QtCore import QThread, pyqtSignal

import argparse
import configparser
import platform
import shutil
import time
import cv2
import torch
import torch.backends.cudnn as cudnn


from yolov5.utils.downloads import attempt_download
from yolov5.models.experimental import attempt_load
from yolov5.models.common import DetectMultiBackend
from yolov5.utils.datasets import LoadImages, LoadStreams
from yolov5.utils.general import LOGGER, check_img_size, non_max_suppression, scale_coords, check_imshow, xyxy2xywh
from yolov5.utils.torch_utils import select_device, time_sync
from yolov5.utils.plots import Annotator, colors
from deep_sort_pytorch.utils.parser import get_config
from deep_sort_pytorch.deep_sort import DeepSort

Part 1: Models not found, despite models being the parent folder.

python3 dashboard.py 
Traceback (most recent call last):
  File "/home/aevas/Desktop/Dashboard_2021_12/dashboard.py", line 25, in <module>
    from trackerThread import trackerDeepSORT
  File "/home/aevas/Desktop/Dashboard_2021_12/trackerThread.py", line 15, in <module>
    from yolov5.models.experimental import attempt_load
  File "/home/aevas/Desktop/Dashboard_2021_12/targetTrack/yolov5/models/experimental.py", line 14, in <module>
    from models.common import Conv
ModuleNotFoundError: No module named 'models'

Part 2: After changing import models.common to import common, it turns out even common cannot be found despite being in the same folder !

python3 dashboard.py 
Traceback (most recent call last):
  File "/home/aevas/Desktop/Dashboard_2021_12/dashboard.py", line 25, in <module>
    from trackerThread import trackerDeepSORT
  File "/home/aevas/Desktop/Dashboard_2021_12/trackerThread.py", line 15, in <module>
    from yolov5.models.experimental import attempt_load
  File "/home/aevas/Desktop/Dashboard_2021_12/targetTrack/yolov5/models/experimental.py", line 14, in <module>
    from common import Conv
ModuleNotFoundError: No module named 'common'

This is how the files are like in the folder models enter image description here

and this is how the import portion of experimental.py looks like

# YOLOv5            
  • Related