Importing library 'RPA.Desktop.OperatingSystem' failed: IndexError: list index out of range Traceback

Hi,

I’m trying to use RPA.Desktop.OperatingSystem library. Though while coding, all the methods under ‘Desktop’ shows up but when I execute the code, it is throwing the errors mentioned below. I’d really appreciate any help that I could get. Thanks in advance.

My code:

*** Settings ***
Library    RPA.Desktop.OperatingSystem

*** Tasks ***
Get computer information
    ${machine}=     Get Machine Name
    Log    ${machine}

ERROR:

Exception has occurred.
Suspended due to logged error: Error in file ‘c:\Azure\feature-dataquality-locations\aIT-RPA\Bots\Test\Test.robot’ on line 2: Importing library ‘RPA.Desktop.OperatingSystem’ failed: IndexError: list index out of range
Traceback (most recent call last):
File “C:\program files\python311\Lib\site-packages\RPA\Desktop_init_.py”, line 18, in
import pywinauto
File “C:\program files\python311\Lib\site-packages\pywinauto_init_.py”, line 89, in
from . import findwindows
File “C:\program files\python311\Lib\site-packages\pywinauto\findwindows.py”, line 42, in
from . import controls
File “C:\program files\python311\Lib\site-packages\pywinauto\controls_init_.py”, line 36, in
from . import uiawrapper # register “uia” back-end (at the end of uiawrapper module)
^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\program files\python311\Lib\site-packages\pywinauto\controls\uiawrapper.py”, line 47, in
from …uia_defines import IUIA
File “C:\program files\python311\Lib\site-packages\pywinauto\uia_defines.py”, line 181, in
pattern_ids = _build_pattern_ids_dic()
^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\program files\python311\Lib\site-packages\pywinauto\uia_defines.py”, line 169, in _build_pattern_ids_dic
if hasattr(IUIA().ui_automation_client, cls_name):
^^^^^^
File “C:\program files\python311\Lib\site-packages\pywinauto\uia_defines.py”, line 50, in call
cls._instances[cls] = super(_Singleton, cls).call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\program files\python311\Lib\site-packages\pywinauto\uia_defines.py”, line 60, in init
self.UIA_dll = comtypes.client.GetModule(‘UIAutomationCore.dll’)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\program files\python311\Lib\site-packages\comtypes\client_generate.py”, line 128, in GetModule
return ModuleGenerator(tlib, pathname).generate()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\program files\python311\Lib\site-packages\comtypes\client_generate.py”, line 244, in generate
GetModule(ext_tlib)
File “C:\program files\python311\Lib\site-packages\comtypes\client_generate.py”, line 128, in GetModule
return ModuleGenerator(tlib, pathname).generate()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\program files\python311\Lib\site-packages\comtypes\client_generate.py”, line 245, in generate
return [_create_module(name, code) for (name, code) in codebases][-1]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\program files\python311\Lib\site-packages\comtypes\client_generate.py”, line 245, in
return [_create_module(name, code) for (name, code) in codebases][-1]
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\program files\python311\Lib\site-packages\comtypes\client_generate.py”, line 206, in _create_module
abs_gen_path = os.path.abspath(g.path[0]) # type: ignore
~~~~~~~~~~^^^
PYTHONPATH:
C:\Program Files\Python311
C:\program files\python311\Lib
C:\program files\python311\Lib\site-packages
c:\Users\vcharan.vscode\extensions\robocorp.robotframework-lsp-1.12.0\src\robotframework_debug_adapter
C:\Azure
c:\Users\vcharan.vscode\extensions\robocorp.robotframework-lsp-1.12.0\src
c:\Users\vcharan.vscode\extensions\robocorp.robotframework-lsp-1.12.0\src\robotframework_ls\vendored
C:\Program Files\Python311\python311.zip
C:\Program Files\Python311\DLLs
C:\Program Files\Python311\Lib
C:\Program Files\Python311
C:\Program Files\Python311\Lib\site-packages
C:\Program Files\Python311\Lib\site-packages\win32
C:\Program Files\Python311\Lib\site-packages\win32\lib
C:\Program Files\Python311\Lib\site-packages\Pythonwin

Hello,

I tried replicating the error in a clean venv using python 3.11.8. without luck.
From the information given my best guess is saying your install of rpaframework or robotframework libraries might be faulty in some way. Maybe someone else can give more insight?

I would try reinstalling your libraries and seeing if that makes a difference.
The steps i took in my command prompt to get it to work are below :slightly_smiling_face:

#setting up venv
python -m venv venv

#Activating the virtual environment
cd /venv/Scripts
activate.bat

#installing libraries
pip install robotframework
pip install rpaframework

#navigating to and executing your .robot file
cd PATH/TO/YOUR/ROBOTFILE
robot YourCode.robot

Hopefully this helps!

Issues is coming from comtypes python package.

Quick glance thru the code shows that the python code of comtypes is trying to write a python wrapper files for COM objects into the same directory where comtypes is installed into. If any of the steps during this generation phase fails, result does match the stacktrace here. One reason for this would be that rpaframework and comtypes have been installed into global python env with different user or with administrator rights and then the executing user does not have access to write into the same directory.

These errors are logged during the initialization of comtypes via python’s logger but not shown here. I’d start by running robot in verbose and grepping for comtypes.gen string and see what they say or try to install all your dependencies into venv and see if that helps.

1 Like

Thank you for your response. I tried reinstalling the libraries, but the issue persisted. However, after adding ‘Library pywinauto’ in settings, the problem was resolved. I’m still trying to understand the reason behind this. I do believe that there might be an issue with my installation of Robot Framework libraries.

You are absolutely right! rpaframework was installed into global python env with admin user, and the executing user does not have access to write into the same directory.

I did reinstall all dependencies, and I had to add ‘Library pywinauto’ in settings to fix the issue. Is there any reason why adding this to the settings fixes the issue?

Thank you for your inputs. I really appreciate your help.