This topic describes how to use a PyODPS node in a DataWorks workspace to reference a third-party package.

  1. Log on to the DataWorks console. In the left-side navigation pane, click Workspaces. On the Workspaces page, find the target workspace and click Data Analytics in the Actions column.
  2. On the Data Analytics tab, click the target workflow under Business Flow, right-click MaxCompute, and then choose Create > Resource > Python.
  3. In the Create Resource dialog box that appears, set Resource Name and select Upload to MaxCompute.
  4. Click OK.
  5. On the configuration tab of the created Python resource, enter the code of the third-party package to be referenced. In this example, enter the following code:
    # import os
    # print os.getcwd()
    # print os.path.abspath('.')
    # print os.path.abspath('..')
    # print os.path.abspath(os.curdir)
    
    def printname():
        print 'test2'
    print 123

    Click the Submit icon.

  6. Click the target workflow, right-click MaxCompute, and then choose Create > PyODPS 2.
  7. In the Create Node dialog box that appears, set Node Name and click Commit.
  8. On the configuration tab of the PyODPS 2 node, enter the code for referencing the third-party package. In this example, enter the following code:
    ##@resource_reference{"test2.py"}
    
    import sys 
    import os
    sys.path.append(os.path.dirname(os.path.abspath('test2.py'))) # Import the resource to the workspace.
    import test2 # Reference the resource.
    test2.printname() # Call the method.
    Note The ##@resource_reference{"test2.py"} statement is required to reference the created Python resource.
  9. Click the Run icon to run the PyODPS 2 node. You can view the running result of the PyODPS 2 node on the Runtime Log tab.