简体   繁体   中英

Python Django Unable To Import Module Within Module

Not entirely sure how to ask this, I tried searching but couldn't find an answer possibly due to how I phrased it.

Lets say I have:

myapp/myapp/script1.py

myapp/myapp/main/

myapp/myapp/main/app.py

myapp/myapp/main/util/script2.py

script2.py imports with the following:

import myapp.script1

I can run script2.py perfectly fine from the console. However when I try to import script2.py into my app.py using:

import main.util.script2.py

I get an error saying:

Exception Type: ImportError

Exception Value: No module named cb2

cb2 is a dependency in script1.py. However running from script2.py on its own in the console it imports the cb2 with no issue. I've tried import cb2 on its own directly but still get the same issue. cb2 is listed in dependencies in my Config file. Is this a pathing issue that I have overlooked? I'm still pretty new to Django/Python. Sorry if my question is not explained very well I can provide more information if that would help.

尝试将import语句从一开始就移到实际需要import模块的具体函数中,这是避免相互导入的一种方法。

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