Skip to main content
Solved

Importing a module in the workspace's directory into PythonCaller


marcel.garate
Participant
Forum|alt.badge.img+2

  

TLDR: sys.path does not contain FME_MF_DIR, so I can’t directly import a local Python module. This contradicts FME’s documentation. What am I missing?

 

Hi all,

I’m having problems importing a local Python module located in the same directory as my FME workspace. Could you help me find out what the problem is or am I missing something?

According to the PythonCaller documentation,

FME will search both the standard Python module locations and the workspace location to find the module to be imported.

However, when I try to import my module in <workspace directory>/feature_processor/__init__.py with the following code:

from feature_processor import FeatureProcessor

I get the following exception:

Message Type: fme::internal::_v0::py::Exception
Python Exception <ModuleNotFoundError>: No module named 'feature_processor'
Error executing string `from feature_processor import FeatureProcessor
'
Factory proxy not initialized
FeatureProcessor (PythonFactory): PythonFactory failed to process feature
An error has occurred. Check the logfile above for details

 

To avoid this error, I’ve appended FME_MF_DIR to sys.path, but I’d like to understand why it is that I can’t directly import my module.

I’m currently using FME Form 2024.1.1.1 on Windows 10 x64

Thanks for the help.

Best answer by marcel.garate

Hi ​@takashi

Thank you for your very detailed answer, your examples helped me find the problem:

A workspace parameter of type “Scripted Value” somehow interferes with the appendment of the workspace path into sys.path. For this reason, this has to be done manually.

View original
Did this help you find an answer to your question?

4 replies

takashi
Influencer
  • May 24, 2025

Hi ​@marcel.garate ,

If the FeatureProcessor class is defined in this file saved in the same folder as the “__init__.py” file,

<workspace directory>/feature_processor/feature_processor.py

try writing this code into the “__init__.py”. Just be aware that the preceding . is required in this case. 

from .feature_processor import FeatureProcessor

 


marcel.garate
Participant
Forum|alt.badge.img+2

Hi ​@takashi

Thank you for your reply. If I understand you correctly, this is for the relative import within my module. However, my problem is importing the module within FME Form. Once I get the path to my module in sys.path, I have no problem importing and running the FeatureProcessor class.


takashi
Influencer
  • May 26, 2025

The preceding . is required if you publish classes/functions defined in other *.py files through "from ... import" statement in the "__init__.py". See the case 1 in the attached workspace examples.

In fact, there are several ways to import a custom pythom module saved in the workspace directory. In some cases, "__init__.py" is not required. See also other cases in the attachment.


marcel.garate
Participant
Forum|alt.badge.img+2
  • Author
  • Participant
  • Best Answer
  • May 26, 2025

Hi ​@takashi

Thank you for your very detailed answer, your examples helped me find the problem:

A workspace parameter of type “Scripted Value” somehow interferes with the appendment of the workspace path into sys.path. For this reason, this has to be done manually.


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