0
root_package
|---main_package
|    |--__init__.py
|    |--main.py 
|---write_to_file
|    |--__init__.py
|    |--write.py  
|
|---__init__.py

I'm tryin to access a function that's in main.py from write.py like this:

write.py

from root_package.main_package.main import getProduct

and I get the following error: No module named 'root_package'

I know this is basic and most asked question, but I can't find the answer from other posts. I'm just not seeing what is wrong. Thanks

EDIT: I'm trying to run write.py script like this:

root_package\write_to_file\write.py python write.py

4
  • 1
    Where are you running your main.py script from? If from root_package directory, try from main_package.main import getProduct. Commented Mar 8, 2023 at 11:07
  • @YevhenKuzmovych oh, I forgot to add that. I'm actually trying to run write.py script. Naming isn't the best, but yeah.. Commented Mar 8, 2023 at 11:13
  • So you run it from write_to_file directory? Try using from main_package.main import getProduct and run it from root_package with python write_to_file/write.py Commented Mar 8, 2023 at 11:17
  • @YevhenKuzmovych Yes, but now I'm getting "no module named 'main_package' " :/ Commented Mar 8, 2023 at 11:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.