[Help]How to use relative import in actions.py

In my actions.py, I use relative import to import other module. When I try to start the action server with the command ‘rasa run actions’, it results in error: ImportError: attempted relative import with no known parent package

Please tell me how should I start action server with relative import?

Hi @yhdrytjd,

can you please post your directory/project structure with everything you want to import and could you please post a few infos about your Rasa version etc. ?

Regards Julian

Hi, the root directory contains the actions.py, domain.yml, etc.

root/
      lib/
          constants.py

In the actions.py, I use relative import: from .lib import constants

it results in error: ImportError: attempted relative import with no known parent package.

I am using rasa 1.6.0

Hi @yhdrytjd,

did you specify lib/ as a package-folder by putting an __init__.py file into it? If so, you can remove the . from .lib to import.

Regards Julian

I tried remove the __init__.py from lib/, but relative import with .lib still does not work with the command ‘rasa run actions’.

I want to test my scripts in lib/ without running rasa actions. The starting folder is in lib/ rather than root/. I need to use relative import to reference the scripts.

Hi @yhdrytjd,

okay, I am going to rebuild your setup and provide some feedback but I need a bit of time for that since I am involved in something else currently.

Stay tuned! :slight_smile: Regards
Julian