Solved

How can I properly use an anaconda python environment in PythonCaller?


Badge +1

I am trying to implement some python code that uses geopandas library, which I have installed in a local python environment on anaconda. I have made a few attempts to run it directly from PythonCaller transformer with no sucess: 

  • On fme desktop tools, I configured the fme python interpreter to get the .dll from the environment.
  • I also set the PYTHONHOME to the folder of the environment.

However, those configuration didn't work and I kept getting the error: No module named: "geopandas".

 

So, I also included this lines at the beginning of the code in PythonCaller:

import sys
sys.path.append(r"C:\Users\[username]\anaconda3\envs\[environment-name]\Lib\site-packages")

After that, I get a new error:

Python Exception <ModuleNotFoundError>: No module named 'pyproj._network'

 

I check on the "site-packages" folder and I have the pyproj package installed, so I don't know what could be causing this error,  in my anaconda environment the code runs without errors. 

 

Do you know what could be causing it?

icon

Best answer by juandiegoboh 8 June 2022, 18:16

View original

3 replies

Userlevel 4

Check if some of the tips here can help: https://community.safe.com/s/question/0D54Q000080hIw2SAE/configuring-anaconda-environment-in-fme

Badge +1

Hi David, thanks for sharing it, I've already read it. I did what people suggest in that post, unfortunately, my script still doesn't run correctly, I think it's due to a compatibility issue between the python of the anaconda install and FME.

 

But I have made it work, I have to recreate the libraries I have in my environment (ie leave out that env in my case) in the local fme python libraries installation (C:\\Users\\[username]\\Documents\\FME\\Plugins\\Python), which is not that easy as Geopandas has some problems in its dependencies when installing it using pip, then I updated to the latest version of FME (2022) and still had to change the python interpreter to use the version 3.9+, after that I successfully run the python script using geopandas.

Badge +8

Hi David, thanks for sharing it, I've already read it. I did what people suggest in that post, unfortunately, my script still doesn't run correctly, I think it's due to a compatibility issue between the python of the anaconda install and FME.

 

But I have made it work, I have to recreate the libraries I have in my environment (ie leave out that env in my case) in the local fme python libraries installation (C:\\Users\\[username]\\Documents\\FME\\Plugins\\Python), which is not that easy as Geopandas has some problems in its dependencies when installing it using pip, then I updated to the latest version of FME (2022) and still had to change the python interpreter to use the version 3.9+, after that I successfully run the python script using geopandas.

Maybe edit your reply so the solution isn't hidden behind the [expand post] link. The first couple of times I read this thread while looking for help I missed the important part.

Reply