Python; Cant import module from other directory

I am trying to decompose my program on python. I have read a lot of information and other answers about how import works, but still cant understand how exactly.

I want to use my module Graph.Graph2D for implementation in InteractiveGraph2D. Before importing it, I add path to this module. But it tells NameError: name 'Graph2D' is not defined.

Project path:


Module path:



# ~/MyData/Python/Pygame/RoadSearchAlgorithm/src/Graph_package/

    from Graph.Graph2D import Graph2D, ...
except Exception as e:
    assert (e)

class InteractiveGraph2D(Graph2D):

What’s the problem?

I tried to look at paths, list of imported modules. The Graph module presented in it.

>Solution :

You say that the modules path is ~/MyData/Python/Pygame/MY_MODULES/Graph while in the python code you added the string '/home/rayxxx/MyData/Python/MY_MODULES' to the os.path. Maybe the point is this

Leave a Reply