Skip to main content
Solved

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

  • February 12, 2022
  • 3 replies
  • 389 views

takashi
Celebrity

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?

Best answer by danminneyatsaf

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.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

3 replies

danminneyatsaf
Safer
Forum|alt.badge.img+13
  • Safer
  • 485 replies
  • Best Answer
  • February 14, 2022

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.


takashi
Celebrity
  • Author
  • 7842 replies
  • February 14, 2022

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')

 

 

 


franco69
Contributor
Forum|alt.badge.img+6
  • Contributor
  • 164 replies
  • July 19, 2022

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