Skip to main content
Question

Running PyQGIS in FME PythonCaller transformer?

  • September 13, 2018
  • 7 replies
  • 293 views

tono
Contributor
Forum|alt.badge.img+11
  • Contributor

I am trying to get information from a QGIS project and layers and produce a new project based on new analysis results made on FME. (I know that the qgis project file is an xml and so I can read it as an xml, but i am trying to build a bridge between qgis 2.18 and fme desktop 2018)

How to install the PyQGIS module and then using the custom python interpreter in FME Desktop?

I am using QGIS-ltr 2.18.23 (from OSGEO4w64) and FME 2018.1.0.1 (Win64).

7 replies

daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • September 13, 2018

Hi @tono,

Please install the full version of Python on your computer, then see this page on how to install and use a custom Python interpreter in FME, to have your FME use the full version of Python.

Once you have FME running with the full Python, you can install the PyQGIS into the full Python, and the module will be usable within FME.


tono
Contributor
Forum|alt.badge.img+11
  • Author
  • Contributor
  • September 14, 2018

Is there any way of using the python interpreter, already installed for and used by QGIS, into FME desktop? Reading the documentation about PyQGIS, i have seen that the pyhton interpreter is an exe file while FME desktop points to dll's. I am not used to change the Python environment variables or interpreters, so a bit lost here :(


daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • September 14, 2018
tono wrote:

Is there any way of using the python interpreter, already installed for and used by QGIS, into FME desktop? Reading the documentation about PyQGIS, i have seen that the pyhton interpreter is an exe file while FME desktop points to dll's. I am not used to change the Python environment variables or interpreters, so a bit lost here :(

Hi @tono,

 

QGIS's Python should also install a dll. It may be in the Windows\\System32 folder (for 32 bit Python on 32 bit Windows, or 64 bit Python on 64 bit Windows), or in Windows\\SysWOW64 (32 bit Python on 64 bit Windows)

 


tono
Contributor
Forum|alt.badge.img+11
  • Author
  • Contributor
  • September 17, 2018
daveatsafe wrote:
Hi @tono,

 

QGIS's Python should also install a dll. It may be in the Windows\\System32 folder (for 32 bit Python on 32 bit Windows, or 64 bit Python on 64 bit Windows), or in Windows\\SysWOW64 (32 bit Python on 64 bit Windows)

 

There is no *qgis* nor *py* files inside C:\\windows\\System32 folder (I am working on a windows 10 machine, 64 bits, with 64bits QGIS installed (python 2.7)). Any clue/tips?

 

 


daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • September 17, 2018
tono wrote:
There is no *qgis* nor *py* files inside C:\\windows\\System32 folder (I am working on a windows 10 machine, 64 bits, with 64bits QGIS installed (python 2.7)). Any clue/tips?

 

 

There seems to be a python27.dll in Program Files\\QGIS...\\bin. You may want to try that one.

 

 


tono
Contributor
Forum|alt.badge.img+11
  • Author
  • Contributor
  • September 18, 2018
daveatsafe wrote:
There seems to be a python27.dll in Program Files\\QGIS...\\bin. You may want to try that one.

 

 

I have installed QGIS gjennom OSGEO4W64. So my python27.dll is inside:

 

C:\\OSGeo4W64\\bin and it does not work. I am using pythonhome:C:\\OSGeo4W64\\apps\\qgis-ltr\\python

 

And from pythoncaller, calling "from qgis.core import *" I get:

 

 

The user-specified Python interpreter `C:\\OSGeo4W64\\bin\\python27.dll' is version 2.7 with PYTHONHOME `C:\\OSGeo4W64\\apps\\qgis-ltr\\python'

 

Python version 2.7 loaded successfully

 

In a future release, FME will have reduced support for Python 2.7. Please review http://fme.ly/py27 for further information

 

ImportError: No module named site

 

 

So FME reads the right interpreter, but why is not finding "site" module??

 

 


daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • September 18, 2018
tono wrote:
I have installed QGIS gjennom OSGEO4W64. So my python27.dll is inside:

 

C:\OSGeo4W64\bin and it does not work. I am using pythonhome:C:\OSGeo4W64\apps\qgis-ltr\python

 

And from pythoncaller, calling "from qgis.core import *" I get:

 

 

The user-specified Python interpreter `C:\OSGeo4W64\bin\python27.dll' is version 2.7 with PYTHONHOME `C:\OSGeo4W64\apps\qgis-ltr\python'

 


Python version 2.7 loaded successfully

 


In a future release, FME will have reduced support for Python 2.7.  Please review http://fme.ly/py27 for further information

 


ImportError: No module named site

 

 

So FME reads the right interpreter, but why is not finding "site" module??

 

 

Hi @tono,

 

You probably need to add QGIS's Python to the python path using sys.path.append(). In your case, this would be:

 

sys.path.append('C:\\OSGeo4W64\\apps\\Python27\\lib')

Reply


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