Import Module from Package Leads to ModuleNotFoundError

I created a rasa chatbot that I want to integrate into a larger project. I am struggling with finding the proper structure for my project. So far, my project is structured as such:

RecipeProject
|   
\---RecipeDSS
    |   __init__.py
    |   
    +---chatbot
    |   |   actions.py
    |   |   config.yml
    |   |   credentials.yml
    |   |   domain.yml
    |   |   endpoints.yml
    |   |   __init__.py
    |   |   
    |   +---data
    |   |       nlu.md
    |   |       stories.md
    |   |       
    |   +---models
    |   |       20200113-112156.tar.gz
    |           
    +---recipeSearch
    |   |   Api.py
    |   |   RecipeSearch.py
    |   |   User.py
    |   |   __init__.py
    |   |   
    |   +---testing
    |   |       __init__.py

In actions.py, I want to include an import statement for Api.py, which is under the recipeSearch package. In my IDE, I can do this successfully with a statement such as: from RecipeDSS.recipeSearch import Api

However, I do not have success from the command line when running my action server. I tried:

  1. With my dir set to .\RecipeDSS, running: rasa run actions --actions chatbot.actions, produces ModuleNotFoundError: No module named ‘RecipeDSS.recipeSearch’
  2. With my dir set to .\chatbot, running: rasa run actions, produces the same error

Is there somewhere else I should be placing the rasa package (chatbot)/restructure my project? Or how else should I be importing functions from Api.py into actions.py?

Thanks :slight_smile:

When you run it from the command line without installing your project as a package, it is looking for the module relative to your current path i.e. in a subfolder called “RecipeDSS”. If you cd up one level and run rasa run actions --actions RecipeDSS.chatbot.actions, the import should work fine.

1 Like

Thanks for the reply. Unfortunately I still ran into the ModuleNotFoundError with this approach when running in via command line (but not in my IDE). As a solution, I restructured my code and put the recipeSearch folder as a subfolder within chatbot. The imports work fine them in cmd.

Glad to hear you could resolve it

1 Like