Solved

Can you use win32com with the Python interpreter in FME Desktop?

  • 13 February 2022
  • 3 replies
  • 58 views

Userlevel 3
Badge +17

FME 2021.2.2 on Windows 11

 

To use the win32com module with a PythonCaller, I have installed the module with this command.

fme.exe python -m pip install pywin32 --target C:\\Users\\<user>\\Documents\\FME\\Plugins\\Python

 

cf. Installing Python Packages to FME Desktop

 

In the PythonCaller script, use the module with this code.

from win32com.client import Dispatch

 

This error message appears when run the workspace.

Python Exception <ModuleNotFoundError>: No module named 'win32api'

 

I believe that the script is not wrong, since the workspace can be run if I install the module into an external Python interpreter and use it as Custom Python Interpreter for FME.

 

Can you use win32com into with the Python interpreter bundled in FME Desktop?

icon

Best answer by danminneyatsaf 14 February 2022, 21:50

View original

3 replies

Userlevel 2
Badge +10

Hi @Takashi Iijima​, there's a few additional steps required to get the pywin32 module working with FME after installing following the instructions here.

 

You will need to copy the two dll's (pythoncom38.dllpywintypes38.dll) in the pywin32_system32 directory of the target install location of win32com module to the FME install directory. Note two dll's installed on your system may be named differently if using a different version of FME (eg. pythoncom39.dll & pywintypes39.dll if using FME 2022).

Restart FME if it is currently open.

 

If you are still running into errors, add the following lines to your script before importing win32com in your script. You may need to change the paths to point to where you have downloaded win32com.

 

import sys
 
sys.path.insert(0,r'C:\Users\<user>\Documents\FME\Plugins\Python\python38\win32')
 
sys.path.insert(0,r'C:\Users\<user>\Documents\FME\Plugins\Python\python38\win32\lib')
 
sys.path.insert(0,r'C:\Users\<user>\Documents\FME\Plugins\Python\python38\Pythonwin')

 

Note: as the pywin32 module is non-universal, ensure the correct Python and bit-version of the module is downloaded. It is also highly recommended to specify the major and minor version for the destination folder when installing as it is non-universal.

Userlevel 3
Badge +17

Hi @Takashi Iijima​, there's a few additional steps required to get the pywin32 module working with FME after installing following the instructions here.

 

You will need to copy the two dll's (pythoncom38.dllpywintypes38.dll) in the pywin32_system32 directory of the target install location of win32com module to the FME install directory. Note two dll's installed on your system may be named differently if using a different version of FME (eg. pythoncom39.dll & pywintypes39.dll if using FME 2022).

Restart FME if it is currently open.

 

If you are still running into errors, add the following lines to your script before importing win32com in your script. You may need to change the paths to point to where you have downloaded win32com.

 

import sys
 
sys.path.insert(0,r'C:\Users\<user>\Documents\FME\Plugins\Python\python38\win32')
 
sys.path.insert(0,r'C:\Users\<user>\Documents\FME\Plugins\Python\python38\win32\lib')
 
sys.path.insert(0,r'C:\Users\<user>\Documents\FME\Plugins\Python\python38\Pythonwin')

 

Note: as the pywin32 module is non-universal, ensure the correct Python and bit-version of the module is downloaded. It is also highly recommended to specify the major and minor version for the destination folder when installing as it is non-universal.

Thank you for your input @danminneyatsaf​ 

Finally I was able to execute the script with the Python interpreter in FME 2021.2 Desktop.

 

What I did:

(1) Install win32com (pywin32) module.

fme.exe python -m pip install pywin32 --target C:\Users\<user>\Documents\FME\Plugins\Python\python38

 

(2) Copy these two dlls within "C:\Users\<user>\Documents\FME\Plugins\Python\python38\pywin32_system32" to FME 2021.2 Desktop install directory.

pythoncom38.dll

pywintypes38.dll

 

(3) Add these codes at the top of the script.

import sys
sys.path.insert(0, r'C:\Users\<user>\Documents\FME\Plugins\Python\python38\win32')
sys.path.insert(0, r'C:\Users\<user>\Documents\FME\Plugins\Python\python38\win32\lib')

 

 

 

Badge +6

Thank you for your input @danminneyatsaf​ 

Finally I was able to execute the script with the Python interpreter in FME 2021.2 Desktop.

 

What I did:

(1) Install win32com (pywin32) module.

fme.exe python -m pip install pywin32 --target C:\Users\<user>\Documents\FME\Plugins\Python\python38

 

(2) Copy these two dlls within "C:\Users\<user>\Documents\FME\Plugins\Python\python38\pywin32_system32" to FME 2021.2 Desktop install directory.

pythoncom38.dll

pywintypes38.dll

 

(3) Add these codes at the top of the script.

import sys
sys.path.insert(0, r'C:\Users\<user>\Documents\FME\Plugins\Python\python38\win32')
sys.path.insert(0, r'C:\Users\<user>\Documents\FME\Plugins\Python\python38\win32\lib')

 

 

 

Dear Takashi,

 

which script are you referring to exactly by "(3) Add these codes at the top of the script."?

 

Thanks,

Franco

Reply