Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

~/MyData/Python/Pygame/RoadSearchAlgorithm/src

Module path:

~/MyData/Python/Pygame/MY_MODULES/Graph

Code:

# ~/MyData/Python/Pygame/RoadSearchAlgorithm/src/Graph_package/InteractiveGraph2D.py

...
sys.path.append('./')
sys.path.append('/home/rayxxx/MyData/Python/MY_MODULES')
try:
    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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading