Import custom module in actions.py

Hey,

I made an class in a separate python file that I want to use in actions.py file. If I import, the action server’s logs say this…

from db_api import db_api ModuleNotFoundError: No module named ‘db_api’

this is my directory structure: -actions -init.py - actions.py - db_api.py

@LastWalkerB

Heya!! For example you have weather.py file and you have created the class called

def Weather(city): ----your code

return

Now in action.py

you need to import the weather.py file

from weather import Weather

call the class Weather to get the information from weather.py

I hope this will clear or if I don’t understand your query please explain with example.

Tip: actions.py and weather.py should be at same please.If it is a solution tick it :wink: Good Luck!

Hey! Thanks for the response.

I tried that but it won’t work :confused:

I found a workaround though…I typed this: “from . import <myFileName” then I refered to my class using the module name, like this ".

It worked ;p. But the conventional import [eg from weather import Weather] won’t work in actions.py

@LastWalkerB Heya!! It’s working or not? Yeah, Rasa updates its version more often, I have given you the idea and concept.

yep it does, thanks.

same here. How do I do it? I have api.py in my actions folder but can’t import it in actions.py