Skip to main content
Solved

Python Integration

  • August 2, 2022
  • 9 replies
  • 267 views

I'm trying to use FME purley through Python and have successfully executed the "WorkspaceRunner.py" sample code, calling it via FME:

fme.exe python fmeobjects/samples/Python/WorkspaceRunner/WorkspaceRunner.py

I have since tried to create my own program but which throws an exception that I would appreciate to get some guidance on.

 

Here my code: 

import os
import sys
 
os.add_dll_directory(r"C:\Program Files\FME")
sys.path.append(r"C:\Program Files\FME\fmeobjects\python39")
 
import fmeobjects
 
runner = fmeobjects.FMEWorkspaceRunner()
workspace = "testWorkSpace.fmw"
runner.promptRun(workspace)

Error message:

fmeobjects.FMEException: FMEException: 1: Failure running workspace 'testWorkSpace.fmw'

Importing the FME modules seems to work and I'm using the same interpreter as with the WorkspaceRunner.py sample. "testWorkSpace.fmw" is an empty workspace.

I also found that when executing WorkspaceRunner.py without going through fme.exe i get the following error:

FMEWorkspaceRunner: Error in dialog creation during initialization

 

Best answer by debbiatsafe

Hi @sondre​ 

I'm sorry to hear you're running into this issue.

 

Are you able to provide more information on the Python environment you're using when running into this error? For example, what version of FME and the Python interpreter is used?

Hello @sondre​ 

I was able to reproduce the error you're seeing when using the fmeobjects.FMEWorkspaceRunner() class with python.org's Python 3.8 and 3.9 interpreters. It appears to be resolved if the FME install directory is inserted into the PATH environment variable in addition to using os.add_dll_directory(). The dialog error may be related to QT and should be resolved by setting the environment variable QT_QPA_PLATFORM_PLUGIN_PATH.

 

For example, the script below completes successfully with FME 2022 and Python 3.9.

import os
import sys
 
os.add_dll_directory(r"C:\Program Files\FME")
os.environ['PATH']=r"C:\Program Files\FME;"+ os.environ['PATH']
sys.path.append(r"C:\Program Files\FME\fmeobjects\python39")
 
## Set QT_QPA_PLATFORM_PLUGIN_PATH environment variable if encountering error about QT or dialogs
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH']=r"C:\Program Files\FME\qtplugins\platforms"
 
import fmeobjects
 
runner = fmeobjects.FMEWorkspaceRunner()
workspace = "testWorkSpace.fmw"
runner.promptRun(workspace)

Are you still encountering errors after running the modified script?

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

9 replies

geogaard
Contributor
Forum|alt.badge.img+15
  • Contributor
  • 35 replies
  • August 2, 2022

Hi, can you try adding a Creator transformer in your empty workspace and see if that makes a difference. Running an empty workspace could very well be the issue.


  • Author
  • 4 replies
  • August 2, 2022

Hi, can you try adding a Creator transformer in your empty workspace and see if that makes a difference. Running an empty workspace could very well be the issue.

Hi!

Got the same exception.


geogaard
Contributor
Forum|alt.badge.img+15
  • Contributor
  • 35 replies
  • August 17, 2022

Hi!

Got the same exception.

Did you figure out something more? I didn't have the SDK installed and could not do any more testing :(


debbiatsafe
Safer
Forum|alt.badge.img+21
  • Safer
  • 648 replies
  • August 31, 2022

Hi @sondre​ 

I'm sorry to hear you're running into this issue.

 

Are you able to provide more information on the Python environment you're using when running into this error? For example, what version of FME and the Python interpreter is used?


debbiatsafe
Safer
Forum|alt.badge.img+21
  • Safer
  • 648 replies
  • Best Answer
  • September 9, 2022

Hi @sondre​ 

I'm sorry to hear you're running into this issue.

 

Are you able to provide more information on the Python environment you're using when running into this error? For example, what version of FME and the Python interpreter is used?

Hello @sondre​ 

I was able to reproduce the error you're seeing when using the fmeobjects.FMEWorkspaceRunner() class with python.org's Python 3.8 and 3.9 interpreters. It appears to be resolved if the FME install directory is inserted into the PATH environment variable in addition to using os.add_dll_directory(). The dialog error may be related to QT and should be resolved by setting the environment variable QT_QPA_PLATFORM_PLUGIN_PATH.

 

For example, the script below completes successfully with FME 2022 and Python 3.9.

import os
import sys
 
os.add_dll_directory(r"C:\Program Files\FME")
os.environ['PATH']=r"C:\Program Files\FME;"+ os.environ['PATH']
sys.path.append(r"C:\Program Files\FME\fmeobjects\python39")
 
## Set QT_QPA_PLATFORM_PLUGIN_PATH environment variable if encountering error about QT or dialogs
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH']=r"C:\Program Files\FME\qtplugins\platforms"
 
import fmeobjects
 
runner = fmeobjects.FMEWorkspaceRunner()
workspace = "testWorkSpace.fmw"
runner.promptRun(workspace)

Are you still encountering errors after running the modified script?


  • Author
  • 4 replies
  • January 9, 2023

Hi @debbiatsafe​ , I still get this exception:

fmeobjects.FMEException: FMEException: 1: Failure running workspace 'testWorkSpace.fmw'

I am currently using the trial version of FME 2022 with Python 3.9. 


dustin
Influencer
Forum|alt.badge.img+31
  • Influencer
  • 627 replies
  • January 9, 2023

Hi @debbiatsafe​ , I still get this exception:

fmeobjects.FMEException: FMEException: 1: Failure running workspace 'testWorkSpace.fmw'

I am currently using the trial version of FME 2022 with Python 3.9. 

@sondre​ You need to include the full path to the workspace, not just the name. See this link for more info: Run an FME Workspace from Python using FMEWorkspaceRunner (safe.com)


  • Author
  • 4 replies
  • January 9, 2023

@sondre​ You need to include the full path to the workspace, not just the name. See this link for more info: Run an FME Workspace from Python using FMEWorkspaceRunner (safe.com)

Wow, no more exception! Thought it would look in the current work directory for it.

Thanks!


  • Author
  • 4 replies
  • January 9, 2023

Hello @sondre​ 

I was able to reproduce the error you're seeing when using the fmeobjects.FMEWorkspaceRunner() class with python.org's Python 3.8 and 3.9 interpreters. It appears to be resolved if the FME install directory is inserted into the PATH environment variable in addition to using os.add_dll_directory(). The dialog error may be related to QT and should be resolved by setting the environment variable QT_QPA_PLATFORM_PLUGIN_PATH.

 

For example, the script below completes successfully with FME 2022 and Python 3.9.

import os
import sys
 
os.add_dll_directory(r"C:\Program Files\FME")
os.environ['PATH']=r"C:\Program Files\FME;"+ os.environ['PATH']
sys.path.append(r"C:\Program Files\FME\fmeobjects\python39")
 
## Set QT_QPA_PLATFORM_PLUGIN_PATH environment variable if encountering error about QT or dialogs
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH']=r"C:\Program Files\FME\qtplugins\platforms"
 
import fmeobjects
 
runner = fmeobjects.FMEWorkspaceRunner()
workspace = "testWorkSpace.fmw"
runner.promptRun(workspace)

Are you still encountering errors after running the modified script?

This worked but I had to set the full path to the workspace as well.

Thanks!