0

I am developing a custom tool in Alteryx Designer and using the Alteryx Python SDK for the implementation. However, I am facing a ModuleNotFoundError when trying to import the AlteryxPythonSDK module. Here's my code:


from ayx import Alteryx
import AlteryxPythonSDK as Sdk

def process_tool(input_anchor, output_anchor):
    # Read the incoming data from the input anchor
    incoming_record_info = input_anchor.get_record_info(input_anchor)

    # Create the outgoing data with the same structure as the incoming data
    outgoing_record_info = Sdk.RecordInfo(input_anchor)
    outgoing_record_info.init_from_input_record_info(incoming_record_info)

    # Set the predefined column names for row number 3
    predefined_columns = ['Column A', 'Column B', 'Column C', 'Column D', 'Column E']

    # Create a new row for the column names
    outgoing_row = outgoing_record_info.construct_record()

    # Write the predefined column names to the outgoing row
    for idx, column_name in enumerate(predefined_columns):
        outgoing_row[idx] = column_name

    # Push the outgoing row to the output anchor
    output_anchor.push_record(outgoing_row)

    # Forward the incoming data to the output anchor
    for record in input_anchor:
        output_anchor.push_record(record)

# Instantiate the Alteryx tool object
tool = Sdk.AlteryxTool(1, 1)

# Get the input and output anchors
input_anchor = tool.get_input_anchor(0)
output_anchor = tool.get_output_anchor(0)

# Process the tool using the custom function defined above
process_tool(input_anchor, output_anchor)

When running the script, I get the following error:

ModuleNotFoundError: No module named 'AlteryxPythonSDK'

I have tried installing the ayx-python-sdk package using pip, but it says that the requirement is already satisfied.

1: I have upgraded pip to the latest version 2: After running the pip did restart the application and system just to make sure all is in sync 3: Checked a sample code which not using python sdk, and it is working.

1 Answers1

0

As per the answers given on Alteryx forums, the following is a working solution. which is

  • Adding plugins folder to sys.path of code.
  • Adding Alteryx bin folder to the PATH environment variable.
import sys, os
sys.path.append(r"C:\Program Files\Alteryx\bin\Plugins")
os.environ['PATH'] += r";C:\Program Files\Alteryx\bin"
import AlteryxPythonSDK as sdk

Reference

Zero
  • 1,807
  • 1
  • 6
  • 17
  • Thank you @Zero , Yes I went through to their forum and posted my problem there as well. I have tried including the bin folder to the Path envt variable earlier, but Still no luck. – usama nomani Jul 26 '23 at 10:46
  • You can refer to their [documentation](https://help.alteryx.com/developer-help/python-engine-sdk) as well. – Zero Jul 26 '23 at 10:57
  • One more thing to mention, I have tried installing it directly in my Python (outside the Alteryx), but It keeps throwing the error "Exit with subprocess". Unsure if this is related as within Alteryx it says requirement satisfied – usama nomani Jul 26 '23 at 11:02
  • Directly in python?? Using pip or conda or using a python code or script to install it? – Zero Jul 26 '23 at 11:20
  • in VS Code, using pip – usama nomani Jul 26 '23 at 12:22