ModuleNotFoundError: No module named 'layout_colorwidget'

Running PyQt6 on a Mac (Big Sur 11.2.3) with Atom 155.0 as my IDE.

Trying to replicate the example on p. 71 of the book (PyQt6 edition):

import sys
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QApplication, QMainWindow, QVBoxLayout,QWidget
from layout_colorwidget import Color

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("My App")
        layout = QVBoxLayout()
        layout.addWidget(Color("red"))
        layout.addWidget(Color("green"))
        layout.addWidget(Color("blue"))
        widget = QWidget()
        widget.setLayout(layout)
        self.setCentralWidget(widget)

app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec()

Obtain error message, “ModuleNotFoundError: No module named ‘layout_colorwidget’”

Hi @Paul_Fishback welcome to the forum!

The code for the layout_colorwidget file is given in the previous code block – this needs to be saved to a separate file with the name layout_colorwiget.py so it can be imported. This isn’t exactly clear, so I need to improve this.

You can also find the file in the source code downloads with the book, in the same folder with the layout examples.