Ahmad Abogozeh
Ahmad Abogozeh

Reputation: 23

import in python file has imported file

I have python project like

/project
|__main.py
|__/graph 
|____grapher.py
|____object_map_genaration.py

But I got this error:

ModuleNotFoundError: No module named 'object_map_genaration'

Upvotes: 0

Views: 50

Answers (2)

Vincent Bénet
Vincent Bénet

Reputation: 1314

First add an init here:

/project/
|__/main.py
|__/graph/
|____/__init__.py
|____/grapher.py
|____/object_map_genaration.py

Then in grapher.py:

from . import object_map_genaration

And in main.py:

from graph import grapher

Upvotes: 2

Oli
Oli

Reputation: 2602

You need from grapher import object_map_genaration not just import object_map_genaration, since imports are relative to the root of the main file.

Upvotes: 1

Related Questions