Python Engine Usage

This article mainly introduces the configuration, deployment and use of the Python EngineConn in Linkis1.0.

1. Environment configuration before using Python EngineConn

If you want to use the python EngineConn on your server, you need to ensure that the python execution directory and execution permissions are in the user’s PATH.

Environment variable nameEnvironment variable contentRemarks
pythonpython execution environmentAnaconda’s python executor is recommended

Table 1-1 Environmental configuration list

2. Python EngineConn configuration and deployment

2.1 Python version selection and compilation

Python supports python2 and For python3, you can simply change the configuration to complete the Python version switch, without recompiling the python EngineConn version.

  1. #1: CLI to submit tasks for version switching, and set the version Python at the end of the command Version=python3 (python3: the name of the file generated when creating a soft connection, which can be customized)
  2. sh ./ bin/linkis-cli -engineType python-python2 -codeType python -code "print(\"hello\")" -submitUser hadoop -proxyUser hadoop -confMap python. version=python3
  3. #2: CLI to submit the task for version switching, and add the command setting to the version path python Version=/usr/bin/python (/usr/bin/python: the path of the generated file when creating the soft connection)
  4. sh ./ bin/linkis-cli -engineType python-python2 -codeType python -code "print(\"hello\")" -submitUser hadoop -proxyUser hadoop -confMap python. version=/usr/bin/python

Page configuration: Python Engine Usage - 图1

2.2 python engineConn deployment and loading

Here you can use the default loading method to be used normally.

2.3 tags of python EngineConn

Here you can use the default dml.sql to insert it and it can be used normally.

3. Use of Python EngineConn

Ready to operate

Before submitting python on linkis, you only need to make sure that there is python path in your user’s PATH.

3.1 How to use Linkis SDK

Linkis provides a client method to call python tasks. The call method is through the SDK provided by LinkisClient. We provide java and scala two ways to call, the specific usage can refer to JAVA SDK Manual. If you use Hive, you only need to make the following changes:

  1. Map<String, Object> labels = new HashMap<String, Object>();
  2. labels.put(LabelKeyConstant.ENGINE_TYPE_KEY, "python-python2"); // required engineType Label
  3. labels.put(LabelKeyConstant.USER_CREATOR_TYPE_KEY, "hadoop-IDE");// required execute user and creator
  4. labels.put(LabelKeyConstant.CODE_TYPE_KEY, "python"); // required codeType

3.2 How to use Linkis-cli

After Linkis 1.0, you can submit tasks through cli. We only need to specify the corresponding EngineConn and CodeType tag types. The use of Python is as follows:

  1. sh ./bin/linkis-cli -engineType python-python2 -codeType python -code "print(\"hello\")" -submitUser hadoop -proxyUser hadoop

The specific usage can refer to Linkis CLI Manual.

3.3 How to use Scriptis

The way to use Scriptis is the simplest. You can directly enter Scriptis, right-click the directory and create a new python script, write python code and click Execute.

The execution logic of python is to start a python through Py4j Gateway, and then the Python EngineConn submits the code to the python executor for execution.

Python Engine Usage - 图2

Figure 3-1 Screenshot of the execution effect of python

4. Python EngineConn user settings

In addition to the above EngineConn configuration, users can also make custom settings, such as the version of python and some modules that python needs to load.

Python Engine Usage - 图3

Figure 4-1 User-defined configuration management console of python