Python Forum
ModuleNotFoundError: No module named 'graph'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ModuleNotFoundError: No module named 'graph'
#1
Quote:Run the code as install to graph but python3.8 have not accept to install library for graph pip install graph what should to do.
Error:
ModuleNotFoundError: No module named 'graph'
class Graph:
    def __init__(self):
        self.vertices: list = []
        self.adjacency_list: dict = {}
        self.prev: dict = {}
        self.distance: dict = {}
        self.colors: dict = {}
        self.entry: dict = {}
        self.exit: dict = {}
        self.time: int = 0

    def add_vertex(self, label: str):
        self.vertices.append(label)
        self.adjacency_list[label]: list = []
        self.prev[label] = None
        self.distance[label] = 0
        self.colors[label] = "white"

    def add_edge(self, label1: str, label2: str):
        self.adjacency_list[label1].append(label2)
        self.adjacency_list[label2].append(label1)

    def dfs(self, label: str):
        self.colors[label] = "gray"
        self.time += 1
        self.entry[label] = self.time
        for neighbour in self.adjacency_list[label]:
            if self.colors[neighbour] == "white":
                self.prev[neighbour] = label
                self.distance[neighbour] = self.distance[label] + 1
                self.dfs(neighbour)
        self.colors[label] = "black"
        self.time += 1
        self.exit[label] = self.time

    def return_path(self, label: str) -> str:
        if self.prev[label] is None:
            return label
        else:
            return self.return_path(self.prev[label]) + " -> " + label
from graph import Graph

graph = Graph()

my_vertices = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']
# add vertices
for i in range(len(my_vertices)):
    graph.add_vertex(my_vertices[i])

graph.add_edge('A', 'B')
graph.add_edge('A', 'C')
graph.add_edge('A', 'D')
graph.add_edge('C', 'D')
graph.add_edge('C', 'G')
graph.add_edge('D', 'G')
graph.add_edge('D', 'H')
graph.add_edge('B', 'E')
graph.add_edge('B', 'F')
graph.add_edge('E', 'I')

graph.dfs("A")
print(graph.return_path("H"))
Error:
Traceback (most recent call last): File "D:/Python3.8.0/Python/Lib/WordFinder.py", line 43, in <module> from graph import Graph ModuleNotFoundError: No module named 'graph'
Reply
#2
Please post the code that threw the error message ModuleNotFoundError: No module named 'graph'. Also don't omit the rest of the error message. Without a complete error message and the code that threw it, it is very difficult to debug.
Reply
#3
If the Graph class is in the same file, you don't need to import it. Simply remove the import statement and use the Graph class directly.
Reply
#4
@Gribouillis tumb for you right
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  no module named 'docx' when importing docx MaartenRo 1 714 Dec-31-2023, 11:21 AM
Last Post: deanhystad
  Problem with pymodbus - ModuleNotFoundError: No module named 'pymodbus.client.sync' stsxbel 2 22,950 Nov-02-2023, 08:20 AM
Last Post: South_east
  ModuleNotFoundError: No module named 'requests' Serg 18 2,166 Oct-29-2023, 11:33 PM
Last Post: Serg
  Resolving ImportError: No module named gdb (Python in C++) mandaxyz 3 1,313 Oct-04-2023, 02:43 PM
Last Post: mandaxyz
  ModuleNotFoundError: No module named 'PyPDF2' Benitta2525 1 1,392 Aug-07-2023, 05:32 AM
Last Post: DPaul
  ModuleNotFoundError: No module named 'eyed3' Wimpy_Wellington 2 1,228 Jul-10-2023, 03:37 AM
Last Post: Wimpy_Wellington
  How to fix this error: ModuleNotFoundError: No module named 'notears' yaoyao22 2 964 Jul-09-2023, 11:24 AM
Last Post: yaoyao22
  Help with pyinstaller "No module named" korenron 9 8,217 Jun-15-2023, 12:20 PM
Last Post: snippsat
  Problem with Pyinstaller. No module named '_tkinter' tonynapoli2309 0 934 May-15-2023, 02:38 PM
Last Post: tonynapoli2309
  ModuleNotFoundError: No module named 'omsdk.sdkproto' donvito7 4 1,772 Oct-20-2022, 02:56 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020