Amous
Amous

Reputation: 514

ImportError when importing file from another directory

I am playing around with the AIMA python project, but I'm having trouble with importing the logic.py file into main.py. The following is folder structure:

project/
    aima/
        __init__.py
        utils.py
        logic.py
    main.py

I added the folder to my python path variable. Every time I do

# main.py
import aima.logic as logic

I get this error:

File "main.py", line 2, in import aima.logic as logic File "/project/aima/logic.py", line 34, in from utils import ( ImportError: No module named 'utils'

I thought this was strange since logic.py imports the utils file it should be fine since they are under the same directory.

I tried searching for answers, but most of them mention adding to python module search path and adding __init__.py and do not work for me.

Upvotes: 0

Views: 949

Answers (1)

Chetan_Vasudevan
Chetan_Vasudevan

Reputation: 2414

Trying this may be good

  from project.aima import logic

Upvotes: 1

Related Questions