‘Module {Module_Name} not installed’ when running python script using PyQt5

I am trying to build a UI using PyQt5 and python. I built a base using main.qml and some styled qml files in the same directory and it imported fine, but I decided to break everything up into folders so it is more organized but now none of my imports are working no matter what I do.

The new file structure is:

Interface/
│   ├── main.py                  
│   ├── resources.qrc            
│   ├── resources_rc.py          
│   │
│   ├── src/                     
│   │   ├── main.qml            
│   │   │
│   │   ├── Components/          # Directory for custom QML components
│   │   │   ├── Sections/        # Directory for "Sections" module
│   │   │   │   ├── Status.qml
                ├── Title.qml
│   │   │   │   └── qmldir       # qmldir file for "Sections" module
│   │   │   │
│   │   │   └── StyledElements/  # Directory for "StyledElements" module
│   │   │       ├── StyledButton.qml
│   │   │       └── qmldir

StyledElements & Sections contain a qmldir file that looks like:

module Sections
Status 1.0 Status.qml
Title 1.0 Title.qml

My main.py calls it like this:

import os
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQml import QQmlApplicationEngine

def handle_warnings(warnings):
    for warning in warnings:
        print(f"QML Warning: {warning.toString()}")

app = QApplication([])

engine = QQmlApplicationEngine()
engine.warnings.connect(handle_warnings)

# Load QML file
qml_file_path = os.path.abspath('src/main.qml')
print(f"Loading QML file: {qml_file_path}")
engine.load(qml_file_path)

if not engine.rootObjects():
    print("Failed to load QML file.")
    sys.exit(-1)
else:
    print("QML file loaded successfully.")

app.exec_()

sys.exit(app.exec_())

And my main.qml looks like:

import QtQuick 2.15
import QtQuick.Controls 2.15
import StyledElements 1.0
import Sections 1.0

ApplicationWindow {
    title: 'Interceptor'
    visible: true
    width: 700
    height: 600

    Rectangle {
        id: rectangle
        width: 700
        height: 725
        color: 'white'

        Section_Title{}
        StyledButton{}
    }
}

Things I’ve tried:

I have tried putting quote around my import in my main.qml like:

import "StyledElements" 1.0
import "Sections" 1.0

Ive tried setting up import paths like so:

# Set the path to the QML files
engine.addImportPath(os.path.abspath("/Components/Sections"))
engine.addImportPath(os.path.abspath("/Components/StyledElements"))


# Load QML file
qml_file_path = os.path.abspath('src/main.qml')
engine.load(qml_file_path)

Also tried:

engine.addImportPath(os.path.abspath("qrc:/"))
or
engine.addImportPath(os.path.abspath("qrc:/src/main.qml"))

From what I can tell the issue is not to do with loading the main.qml because when i change the path it gives me an error about it not being found and the error seems to be coming from the import in the main.qml.

I tried using a resource file that looks like:

<RCC>
    <qresource prefix="/">
        <file>src/main.qml</file>
        <file>src/Components/Sections/NvStatus.qml</file>
        <file>src/Components/Sections/qmldir</file>
        <file>src/Components/StyledElements/StyledButton.qml</file>
        <file>src/Components/StyledElements/qmldir</file>
    </qresource>
</RCC>

I compiled resource file into python with
pyrcc5 resources.qrc -o resources_rc.py

& imported the new py file using in main.py

import resources_rc

At this point ive spent hours with Chat GPT and google trying to find an answer. Ive tried multiple things that ‘work’ in the sense that they load the qml in the end but cant get the custom module to load. At this point I am not sure how to proceed. Everything I try has lead me to the same issue of the main.qml unable to load the module with the errors:

QML Warning: module "Sections" is not installed
QML Warning: module "StyledElements" is not installed
QML Warning: module "Sections" is not installed
QML Warning: module "StyledElements" is not installed

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật