#๐Ÿ”’ absolute and relative imports

4 messages ยท Page 1 of 1 (latest)

balmy merlin
#

src/main.py

import multiprocessing
from src.mypackage.moduleA import functionA

src/mypackage/moduleA

import moduleB 

src/mypackage/moduleB

#helper functions...

Why is it that running main.py leads to a ModuleNotFoundError: no module named moduleB when it tries to resolve import moduleB in src/mypackage/moduleA?

I've tried to look it up online but i can't make sense of the explanation. It seems to do with the fact that there's a difference between running main.py directly and running main.py as part of the package instead. Would love if someone could help clarify what's going on.

radiant boltBOT
#

@balmy merlin

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

radiant boltBOT
#

@balmy merlin

Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.