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
  ModuleNotFoundError: No module named 'Seal' Anldra12 10 458 Oct-06-2021, 12:12 PM
Last Post: snippsat
  ModuleNotFoundError: No module named 'bluetooth' Error Rovelin 4 524 Aug-31-2021, 04:04 PM
Last Post: Rovelin
  No module named 'pysolar' - even tough pysolar is installed - What am I doing wrong? Jghurt 5 944 May-08-2021, 07:03 PM
Last Post: Jghurt
  ModuleNotFoundError: No module named 'fpdf' KatMac 4 2,135 Apr-19-2021, 01:23 PM
Last Post: KatMac
  ModuleNotFoundError: No module named 'com' aleksg 9 2,905 Dec-14-2020, 05:00 PM
Last Post: Larz60+
Video ModuleNotFoundError: No module named ‘…’ Frank911 1 1,674 Dec-11-2020, 03:59 PM
Last Post: michael1789
  no module named finbert found ErnestTBass 4 1,450 Dec-05-2020, 06:09 PM
Last Post: andrianas
  ModuleNotFoundError: No module named 'fcntl' ErnestTBass 2 7,016 Dec-05-2020, 02:39 PM
Last Post: ErnestTBass
  ImportError: No module named coltson 3 1,233 Nov-21-2020, 10:22 AM
Last Post: Superjoe
  ModuleNotFoundError: No module named 'pyrlang.gen_server' Maxximiliann 0 732 Nov-19-2020, 01:15 AM
Last Post: Maxximiliann

Forum Jump:

User Panel Messages

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