I have a directory called step_2_my_hand, and inside it I have 3 python packages; app.py, general_num_and_suit_list.py and __init__.py.
Inside app.py, I have the following:
from generate_num_and_suit_list import generate_num_list_from_my_hand
def run_num_list_suit_list():
num_list, suit_list = generate_num_list_from_my_hand()
# num list is an integer at this point, and suit list is made up of strings
return num_list, suit_list
And when I run this module directly it works.
In my top level directory, in the same level as the step_2_my_hand directory, I have another app.py, which contains the following:
from all_the_steps_with_coordinates.step_2_my_hand.app import run_num_list_suit_list
Now, when I run this, I get the error:
...
from generate_num_and_suit_list import generate_num_list_from_my_hand
ModuleNotFoundError: No module named 'generate_num_and_suit_list'
But generate_num_and_suit_list.py is a module in the same directory. I checked and there is no spelling mistake.
>Solution :
When you run it in different directory (top-level directory) it will search for generate_num_and_suit_list in that (top-level) directory. Try replacing it with:
from .generate_num_and_suit_list import generate_num_list_from_my_hand
...
Note the . that means "this module".