#πŸ”’ Issues importing module

18 messages Β· Page 1 of 1 (latest)

junior bay
#

Hi there. I'm having some issues importing a function from another python file I have written. Does anyone know why?

Visual studio doesn't complain about being unable to find the folder and file, but when i run the python file, it complains.

ModuleNotFoundError: No module named 'graphs'

fervent walrusBOT
#

@junior bay

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

junior bay
#
import unittest

from graphs.dfs_topological_sort import topological_sort

type AdjacencyList = list[list[int]]


def ctitical_path(adjacency_list: AdjacencyList) -> list[int]:
    """
    Finds the longest path in a directed acyclic graph.
    This represents the critical path of the graph.

    :param adjacency_list: the adjacency list of the input graph
    :return: the critical path of the input graph
    """
    longest = 0
    order = topological_sort(adjacency_list).reverse()

    raise NotImplementedError


class TestBottomUpCriticalPath(unittest.TestCase):

    def test_small(self):
        pass


if __name__ == "__main__":
    unittest.main()
junior bay
#

this file is bottom_up_critical_path.py

#

in the graph_dp folder

winged spoke
#

Add a .. In front of grpahs?

junior bay
#

ImportError: attempted relative import with no known parent package

#

i tried it and it said that

winged spoke
#

One dot? :-p

junior bay
#

Import ".graphs.dfs_topological_sort" could not be resolved

wild stream
#

The place where the script is located, it can’t β€œsee” the graphs folder

junior bay
#

how do i fix that?

#

im trying to organise these files so i didnt really wanna lump hundreds into the same directory

wild stream
#

How are you running the file from within VS Code?

junior bay
#

just running py .\graph_dp\bottom_up_critical_path.py from the root directory of my project

fervent walrusBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.