简体   繁体   中英

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.

试试这个可能很好

  from project.aima import logic

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM