[Help] Error with submodules in actions folder

Hey, I am trying to split my actions for organizing it, this is my folder structure:

  • actions
    • __init__.py
    • file1.csv
    • fil2.yml
    • rasa_actions1.py
    • rasa_actions2.py
    • myimports.py
    • common
      • __init__.py
      • globals.py
      • helpers.py
    • connections
      • __init__.py
      • chat_api.py
    • tables
      • __init__.py
      • table1.py
      • table2.py

Basically I am trying to import all submodules and packages in myimports.py (including rasa_sdk package) and then importing myimports.py in every rasa_actions.py file. In myimports.py, I import submodules like this:

from .connections.chat_api import ChatAPI
from .common.globals import *

In rasa_actions.py, I import myimports.py like this:

from .myimports import *

In my submodules (connections, for example), I import other submodules like this:

from ..common.globals import *

When I try to start the action server with rasa run actions --actions actions in local mode and within my rasa folder, I get the following error: Error

Does anybody know how to solve it?

1 Like

@ElgerJP This might have to do something with you using relative imports. I’d advise on using absolute imports and making sure to append your project’s root directory to PYTHONPATH. Hope this helps!

1 Like

Thank you for the answer! Just to clarify, you suggesting me to add something like this in my actions/__init__.py ?

import sys, os

sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir))

And then over all .py files I should use imports like this?

import actions.tables.table1
from actions.common.globals import *
from actions.myimports import *

@ElgerJP I would avoid using sys.path, try first with running this command in the environment your application is running:

export PYTHONPATH="${PYTHONPATH}:/path/to/your/project/"

# Windows
set PYTHONPATH=%PYTHONPATH%;C:\path\to\your\project\

The absolute imports look good :+1:

1 Like