I am trying to call a python function using Tableau using the Tabpy interface but I am receiving a "No module named interface_v1" error. The steps I have taken:
def call_matlab(a):
return a
SCRIPT_INT("import interface_v1 as inter
return inter.call_matlab(_arg1)", SUM([Body]))
When I try to use the calculated field I receive the above error ModuleNotFoundError in the tabpy server log. I have the workbook and the python file in the same directory, and I also tried to put it in the tabpy\modules\scripts folder.
Note: I am not using tabpy in a virtual environment and I am very new to Tableau so sorry if I am just missing something. Thanks for any help.
Your best solution here is going to be to deploy your 'interface_v1.py' as an endpoint on the tabpy server.
This has the benefit of being much faster, loaded in memory etc... Otherwise you will need to explore loading the file you reference in the same directory that tabpy is running. I would highly suggest the endpoint.
The documentation is fairly straight forward.
Basically you will do the following with your information:
from tabpy.tabpy_tools.client import Client
client = Client('http://localhost:9004/')
def call_matlab(a):
return(a)
client.deploy('call_matlab', call_matlab, 'Pass data to call_matlab')
Then from tableau you should be able to call the named function
script_int("tabpy.query('call_matlab',_arg1)",[COL_TO_SEND])
Obviously adjusting for your specific use case.