Solved

FME Objects API for Python 2.7

  • 8 December 2022
  • 3 replies
  • 6 views

Badge +1

Is there still fmeobjects package supporting python 2.7 in FME 2022.2?

I need to run an FME workspace in ArcMap, which uses python 2.7 and realized there is no fmeobjects for Python 2 in the FME installation folder. Is there an alternative way to do the job?

icon

Best answer by david_r 8 December 2022, 17:07

View original

3 replies

Userlevel 4

Starting with FME 2022.0 and on, Python 2.7 is no longer supported.

For more details, see https://community.safe.com/s/article/python-27-deprecation under the chapter "Behavior in FME 2022.0+"

If you need support for Python 2.7, you'll have to stick with FME 2021.

Userlevel 1
Badge +11

Alternatively, you can choose to upgrade from ArcMap to ArcGIS Pro, which will allow you to use Python 3.x

FME Workbench essentials—ArcGIS Pro | Documentation Available with Data Interoperability license.

Badge

You could also use the "subprocess" python module in python 2.7 and run the FME 2022.2 version that way by pointing to the 64bit fme.exe location. 

 

This should allow you to keep using your python 2.7 in desktop and use the new version of FME. Otherwise,  to use fmeobjects you would need to follow the advice above.

 

Here is an example function using the subprocess package:

import subprocess
# Can pull the standard out and error messages for useful workbench feedback.
def sub__fmeworker(data):
    """ command variable object houses the subprocess cmd string line and houses 3 parameters. where data is a python dictionary.
    1. _workbench = myworkbench.fmw, 2. data[0] = features to run in the workbench, 3. data[1] = log path .txt
 
    The subprocess.Popen() executes the command and retrieves the process outputs to stdout and stderr."""
    text = ''
 
    try:
        fme_ = r"C:\Program Files\FME\fme.exe" ##fme.exe
        command = f'"{fme_}" "{_Workbench}" --FEATURE_TYPES "{data[0]}" --LogFile "{data[1]}"'
        starter = subprocess.STARTUPINFO()
        starter.dwFlags |= subprocess.STARTF_USESHOWWINDOW
 
        process = subprocess.Popen(command,startupinfo=starter, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        stdout, stderr = process.communicate()
        if stderr:
            stderr_de = str(stderr.decode("utf-8")) # Need to remove byte object
            msg = stderr_de.split("\r\n")[0]
            text += data[0] +'  '+ msg
        else:
            stdout_de = str(stdout.decode("utf-8")) # Need to remove byte object
            msg = stdout_de.split("\r\n")
            text += msg+'ERROR########'
    except:  #if the workbench fails add error tag
        text += data[0]+'ERROR########'
    return text

 

Another option would be to create a .bat file with your workbench information and then you can run it in python by just doing a subprocess.call(). I had to use both of these workarounds for a couple projects since the clients still use Desktop and have not migrated to PRO but want the newest fme version.

 

Example .bat:

REM %1 and %2 are arguments - workbench parameters (if you need those) ## this is a comment

"C:\Program Files\FME\fme.exe" <your workbench here>.fmw --FEATURE_TYPES %1 --LogFile %2

 

To run the .bat in python:

import subprocess
bat_file = r"your path \\to bat.bat"
 
args1 = item[0] #the feature class currently being looped through
args2 = item[1] #attached logfile path
subprocess.call([bat_file,args1,args2]) # runs the workbench with parameters (%1, %2)

 

Reply