"Comtypes" pip package not working on built extension

Operating System:
X Windows
Linux
Kit Version:
X107 (Kit App Template)
106 (Kit App Template)
105 (Launcher)
Kit Template:
X USD Composer
USD Explorer
USD Viewer
Custom
GPU Hardware:
A series (Blackwell)
A series (ADA)
A series
50 series
X 40 series
30 series
GPU Driver:
Latest
Recommended (573.xx)
X Other (556.12)

I have built an extension using an extension example provided in Isaac Sim, then switched it up into USD Composer (the one by default built with kit-app-template) .

They are 3 packages i used in my extension: openpyxl, pandas and comtypes.

So i placed this in my extension.toml :
[dependencies]
“omni.kit.uiapp” = {}
“isaacsim.gui.components” = {}
“isaacsim.core.api” = {}

[python.pipapi]
use_online_index = true

requirements = [
“pandas”,
“openpyxl”,
“comtypes”
]

But now, i switched to a cleaner architecture, with 3 extensions :
my_extension.bundle
my_extension.core
my_extension.ui

Where the bundle extension only served as a link (no code in it), just configuration:
[dependencies]
“my_extension.core” = {}
“my_extension.ui” = {}

And i followed this documentation Using Python Pip Packages — kit-app-template that explain how to properly download pip dependencies for an extension so you can package an application, but now I’m running into errors.

For Pandas and openpyxl it’s working, but for comtypes, i’m getting this error:

2394-08-08T15:13:15Z [4,156ms] [Error] [omni.ext._impl.custom_importer] Failed to import python module acn.uc3.core. Error: cannot import name ‘gen’ from ‘comtypes’

An error that i’m not getting when placing the pip package comtypes directly in the extension.toml file


Here is the fix for me. As comtypes generate dynamically comtypes.gen, it creates a problem of permission where the Librairies are stored. Adding the following parameters in the pip.toml in kit-app-template, solved the problem for me. (You might have a similar problem using pywin32).

[[dependency]]
python = “../../_build/target-deps/python”
packages = [
“pandas==2.1.2”,
“openpyxl==3.1.5”
]
target = “../../_build/target-deps/pip_prebundle”

Install comtypes with download first, then extract

[[dependency]]
python = “../../_build/target-deps/python”
packages = [“comtypes==1.4.11”]
target = “../../_build/target-deps/comtypes_download”
download_only = true # Download the wheel file first

Then install from wheel with proper structure

[[dependency]]
python = “../../_build/target-deps/python”
packages = [“../../_build/target-deps/comtypes_download/comtypes-1.4.11-*.whl”]
target = “../../_build/target-deps/pip_prebundle”

I am glad you have figured this out and posted a solution ! Thanks !