Using Python withFME Flow

If you runworkspaces fromFME Flowthat reference Python, the FME Engines must know which Python interpreter to use.Workspaces built withFME Form2016 or later tell FME which version of Python is required to run Python code through thePython Compatibilityworkspaceparameter.

The Python interpreter that the FME Engines actually use is the one that most closely matches the Python Compatibilityworkspaceparameter, which, by default, is FME’s latest supported version of Python 3. To change the default Python interpreter used by the FME Engines, seeChanging the Python Interpreter (Windows only)(below).

Using Additional Python Modules

If you need to reference a Python module fromFME Flowthat is not part of the Python standard library, follow these steps to: 1) Obtain the module (if you have not already); and 2) Upload the module.

Obtaining the Python Module

If you do not already have the Python module you want to reference, install the package with the following command:

> fme.exe python -m pip install <package_name>

For example, to install a package named PyExecJS:

> fme.exe python -m pip install PyExecJS

This command installs the Python module to the FME shared Python user directory:

C:\Users\<user>\Documents\FME\Plugins\Python\python<XY>

Where <user> is the Windows user name and <XY>的Python版本FME Python宰相ter.

Uploading the Python Module

  1. In the C:\Users\<user>\Documents\FME\Plugins\Python directory, locate the files or folders of the Python module you installed, such as .pyc or.py files, as well as any sub-directories that may contain init.pyc or main.pyc files of your package.

  2. Use the Upload tool on theResourcespage of the Web User Interface, and upload these file(s) and/or folder(s) to the folder under Engine\Plugins\python that corresponds to the Python release compatible with the module (for example, python36).

Changing the Python Interpreter (Windows only)

Important  "> ImportantConsider changing the Python interpreteronlyif the Python interpreter shipped withFME Flowis incompatible with third-party Python libraries required to run the Python scripts referenced in yourworkspaces. If you require an Esri ArcGIS Python interpreter to use ArcPy, set thePython Compatibility workspaceparameter to the applicableEsri ArcGIS Python 3.xvalue inFME Workbenchprior to uploading toFME Flow. If set properly in this case, changing the Python interpreter explicitly inFME Flowis not necessary.
Note  "> NoteBeginning withFME Flowversion 2019.0 on Linux, changing the Python interpreter is not supported.

Sometimes you will want to use a Python interpreter other than the ones shipped withFME Flow. In that case, you can change the interpreter through the following procedure:

Note  "> NoteThe Python interpreter specified by this procedure does not guarantee the FME Engines will use the interpreter for allworkspaces. Instead, the FME Engines use the specified interpreter for allworkspaces that have aPython Compatibilityvalue that is compatible with the specified interpreter. If thePython Compatibilityof aworkspaceis not compatible with the specified interpreter, the FME engines use one of their own Python interpreters that is compatible.

Open a command prompt, specifyingRun as administrator, and run the following commands:

FME Flow2018.0 and earlier

<FMEFlowDir>Server/fme/fme.exe APPLY_SETTINGS SYSTEM "Python/Use Custom Python" true

<FMEFlowDir>Server/fme/fme.exe APPLY_SETTINGS SYSTEM "Python/Python Interpreter" c:/<path_to_dll>.dll

Note  "> NoteFor information on how to locate Python dll's (<path_to_dll>), seeChoosing a different Python Interpreterin theFME Community.

FME Flow2018.1 and later

<FMEFlowDir>Server/fme/fme.exe APPLY_SETTINGS SYSTEM "Python/Use Custom Python 64" true

<FMEFlowDir>Server/fme/fme.exe APPLY_SETTINGS SYSTEM "Python/Python Interpreter 64" c:/.dll

<FMEFlowDir>Server/fme/fme.exe APPLY_SETTINGS SYSTEM "Python/Custom Python Home 64" c:/<path_to_python_home>

Note  "> Note <path_to_python_home>is the installation location of Python.