Written by

Allround System Engineer at ASCI nv
Question Kurt Hofman · Feb 10, 2023

Intersystems Iris - embedded python

Hello,

I'm starting testing embedded python and external libraries.

When I try to use the win32api-library I get the following error :

<THROW> *%Exception.PythonException  230 ^^0^ <class 'ModuleNotFoundError'>: No module named 'win32api' -

This is my code :

ClassMethod CreateDocument(path As %String) [ Language = python ]
{
import win32api

...
}
 

The librarie is visible in C:\InterSystems\IRIS\mgr\python\win32.

Am I doing something wrong ?

Regards,

Kurt Hofman,

ASCI nv.

Product version: IRIS 2022.3
$ZV: IRIS for Windows (x86-64) 2023.1 (Build 185U) Tue Jan 31 2023 22:19:19 EST

Comments

Eduard Lebedyuk · Feb 10, 2023

1. Try running:

 cd <IRIS>\bin
 ./irispython "C:\InterSystems\IRIS\lib\python\Scripts\pywin32_postinstall.py" -install

It might fix your error.

If that does not help, add win32 folder to path explitictly and try import again:

import sys
sys.path.append("<IRIS>\Mgr\python\win32")
import win32api
0
Kurt Hofman  Mar 2, 2023 to Eduard Lebedyuk

There is no C:\InterSystems\IRIS\lib\python\Scripts\pywin32_postinstall.py

0
Kurt Hofman  Mar 6, 2023 to Muhammad Waseem

I get this error :

PS C:\Users\kurthofman> C:\InterSystems\IRIS\bin\irispip install --target C:\InterSystems\IRIS\mgr\python win32api
ERROR: Could not find a version that satisfies the requirement win32api (from versions: none)
ERROR: No matching distribution found for win32api

0
Muhammad Waseem  Mar 6, 2023 to Kurt Hofman

Looks like there are some restrictions while installing win32api with pip
Try with pypiwin32 module as below: 
C:\Users\kurthofman> C:\InterSystems\IRIS\bin\irispip install --target C:\InterSystems\IRIS\mgr\python pypiwin32

0
Kurt Hofman  Mar 6, 2023 to Muhammad Waseem

I installed pypiwin32

ClassMethod Test() [ Language = python ]
{
import win32api

}

USER>Do ##class(User.Demo).Test()
 
DO ##CLASS(User.Demo).Test()
^
<THROW> *%Exception.PythonException <THROW> 230 ^^0^ <class 'ModuleNotFoundError'>: No module named 'win32api' -
USER>

0
Lorenzo Scalese  Mar 6, 2023 to Kurt Hofman

Hello @Kurt Hofman ,

I experienced a similar problem the last week while testing a library.

To solve it, I created the PYTHONPATH system environment variable with C:\InterSystems\IRISHealth\lib\python\Lib\site-packages\win32;C:\InterSystems\IRISHealth\lib\python\Lib\site-packages\win32\lib.
IRIS need to be restarted to consider any change in an environment variable.

Check If pythoncom39.dll and pywintypes39.dll exist in the directory C:\InterSystems\IRISHealth\lib\python\Lib\site-packages\win32. If they don't exist, copy them. I don't remember the initial directory of these dll files (maybe C:\InterSystems\IRISHealth\mgr\python\pywin32_system32).

I'm a beginner in Python, so maybe a more simple and clean solution exists...

Hope this help.

0