Skip to main content
Question

Qgis in FME calling pythoncaller


xproch40
Contributor
Forum|alt.badge.img+2

Hey, I’ve been trying to get FME (Feature Manipulation Engine) by Safe Software to use Python libraries from QGIS (like qgis.core) so I can mix their cool features in my temp.fmw workspace. The idea is to use QGIS’s Python (version 3.9) inside FME by setting it up with PowerShell commands. But it’s not working, and here’s why, explained like I’m talking to a 5-year-old and then a bit more grown-up:

The Toy Box Story (Simple Version)
Imagine Python is a kid who needs toy helpers to do jobs—like QGIS toys (for maps) and FME toys (for data tricks). These toys are called DLLs (little helper files). I want Python to borrow toys from both QGIS’s toy box and FME’s toy box at the same time.

Step 1: I told Python, “Look in QGIS’s box (C:\Program Files\QGIS 3.32.0\apps\Python39) and FME’s box (C:\Program Files\FME\python)!” That’s like setting PYTHONHOME and PYTHONPATH.
Step 2: Python found some QGIS toys (like qgis.core), but then it yelled, “Where’s my Qt5Core.dll toy? I can’t play!” It’s like a toy broke because its little helper was missing.
Step 3: I said, “Check FME’s box too for fmesite!” It found fmesite, but then it cried again, “I need fmeobjects.dll and it’s not working!”
Why It’s Broken: Every time Python grabs a toy, it needs more little helper toys (DLLs) to make it work. I keep telling it where to look (using PATH), but it’s like the toy boxes are locked, and Python doesn’t have the key unless QGIS or FME opens them first. We’re mixing two picky toy bosses who don’t share well outside their own games.

The Techy Version (Why DLLs Are the Problem)
Here’s what’s really happening:

QGIS Python Setup: I’m using QGIS’s Python 3.9 (C:\Program Files\QGIS 3.32.0\apps\Python39) because my FME workspace (temp.fmw) needs QGIS libraries like qgis.core for map stuff. I set:
PYTHONHOME = "C:\Program Files\QGIS 3.32.0\apps\Python39"
PYTHONPATH to include QGIS’s libs (C:\Program Files\QGIS 3.32.0\apps\qgis\python) and FME’s (C:\Program Files\FME\python).
FME Needs: The workspace also uses FME’s Python stuff (like fmesite and fmeobjects), which live in C:\Program Files\FME\python.
The DLL Mess:

FME’s Side:
fmesite imports fmeobjects, a Python file (.pyd) that needs fmeobjects.dll from C:\Program Files\FME\bin.
I added C:\Program Files\FME\bin to PATH, but it still fails with ImportError: DLL load failed. Something else (another DLL, like a Microsoft runtime) might be missing, or QGIS’s Python doesn’t like FME’s 64-bit toys.
QGIS’s Side:
qgis.core works at first, but it needs PyQt5.QtCore (for GUI/map stuff), which needs Qt5Core.dll.
Then qgis._core (a deeper QGIS part) needs qgis_core.dll.
I added C:\Program Files\QGIS 3.32.0\bin and \apps\Qt5\bin to PATH, where these DLLs should be, but Python still can’t find them. Errors keep saying DLL load failed.
Why It Fails:

QGIS and FME set up their own “toy boxes” (environments) when you run them normally (like through qgis.bat or FME Workbench). They tweak PATH, PYTHONPATH, and other secret stuff so their DLLs load perfectly.
In PowerShell, I’m building a Frankenstein environment, mixing QGIS’s Python with FME’s libs. But without QGIS’s full setup (like its startup script), the DLLs don’t load—Python can’t find Qt5Core.dll, qgis_core.dll, or fmeobjects.dll properly, even with PATH set.

Questions for You:

Where are Qt5Core.dll, qgis_core.dll, and fmeobjects.dll really hiding on my system? Are they in bin or somewhere else?
How do I run QGIS’s Python in PowerShell with all its DLLs working, then add FME’s stuff?
Is there a better way to mix QGIS and FME toys without this DLL chaos?

 

5 replies

AliAtSafe
Safer
Forum|alt.badge.img+20
  • Safer
  • March 7, 2025

Hi, ​@xproch40.

Thanks for posting to the community. Thanks for the different interpretations of explanation. In the beginning of your thread, you mentioned “The idea is to use QGIS’s Python (version 3.9) inside FME by setting it up with PowerShell commands.”. I’d recommend doing it via command prompt instead as that yields better results and is less troublesome.

For the issue as a whole, before delving deeper here, wondering if you have gone down the route of setting up QGIS Python for FME via Setting a Custom Python Interpreter for FME Form? It does set PYTHONHOME within FME this way too. It might provide some insight to resolve the .dll issues. Let me know if it doesn’t work out and we can explore another avenue.

Thanks!


xproch40
Contributor
Forum|alt.badge.img+2
  • Author
  • Contributor
  • March 12, 2025

Hi, ​@AliAtSafe .

Thanks for the response. Yes, I've gone through the article and have set up the Python paths similarly. I’m familiar with the process as I often use my own local Python. The issue I’m facing is that the Python loads correctly according to the logs (see the images), it finds the correct path, but then reports an issue with it. The setup I have is based on the expectation that it’s trying to find the init.py file, which I placed in the homepath. But still, the Python from QGIS doesn't work.

I tried to solve the problem with this article as well, but it doesn't help. The article: https://stackoverflow.com/questions/65184937/fatal-python-error-init-fs-encoding-failed-to-get-the-python-codec-of-the-file


AliAtSafe
Safer
Forum|alt.badge.img+20
  • Safer
  • March 13, 2025

Hey ​@xproch40.

No problem! Looking at your Python paths here, for the Preferred Python Interpreter parameter, you can try to set it to apps\Python#xx\python#xx.dll and Python Home to apps\Python#xx folder and see if this resolves it as it seems to have libraries in that directory - info is from this Stack Exchange post: https://gis.stackexchange.com/questions/487941/running-pyqgis-processing-algorithms-within-fme-pythoncaller (might provide some insight too).

Best!


xproch40
Contributor
Forum|alt.badge.img+2
  • Author
  • Contributor
  • March 19, 2025

Thank you for your reply. The issue you sent me on the site you posted is that the man in question imported locally and should have imported it globally. That's not entirely my problem. But I tried to set ENV as python home according to him, which he was using. The problem still breaks but there is a new error. With that, now it throws that it doesn't know the qgis library while importing it directly from qgis python. I'm also sending my python code for reference.

I'm beginning to think there's a bigger problem, and that is that I'm mixing apples and pears. Since a lot of the features that are in FME are also in QGIS but have different approaches. Even though it's python and shouldn't be related I'm starting to think it's just that.

 


steveatsafe
Safer
Forum|alt.badge.img+12

Hi ​@xproch40

Your friend is going to be 

import sys

sys.path.append(r"D:\apps\QGIS 3.32.0\apps\qgis-ltr\python")

Add the sys.path.append line before you attempt the import line: 

from qgis.core import QgsPointXY, QgsGeometry 

 

As is often the case with custom interpreter use in FME, you’ll need to add paths for the Python environment to locate/import the modules from.  FME doesn’t automatically look for folders containing python modules in the custom interpreter location. 


As in the case here, even though the PYTHONHOME is set to C:\Program Files\QGIS 3.32.0\apps\Python39\, containing the python39.dll, the actual path to the module location is slightly different C:\Program Files\QGIS 3.32.0\apps\qgis-ltr\python

For the record, sometimes you have to hunt for the folders/files holding the modules and add those paths.  You’ll add any path using the sys.path.append syntax as shared above.

Another helpful test to do in the the code is to list the paths… just so you can see what paths have been ‘identified’ before you start adding additional paths.

for p in sys.path:  

    print(p)

 

As an aside, when using the workspace scripting parameter, Python Compatibility = “Esri ArcGIS Python” FME does indeed add additional paths so that it can find the necessary arcpy modules.

 

Hope this helps…. for the record, my testing was done using FME 2024.1. and QGIS 3.40.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings