GDATASoftwareAG / robotframework-flaui

Windows user interface automation library for Robot-Framework. FlaUILibrary is a wrapper for the FlaUI automation library.
MIT License
61 stars 12 forks source link

Error on library import: Failed to initialize Python.Runtime.dll #191

Closed HackXIt closed 4 months ago

HackXIt commented 4 months ago

I get the following error when attempting to import the library:

[ ERROR ] Error in file 'C:\Users\RINI\#Entwicklung_TechNICK\0_Git_Stash\Testcenter.RobotSuites.HCS.Solution\Testcenter.RobotSuites.HCS.Visocall-IP\src\eval\UIAutomation\SetupLoaderXpath.robot' on line 2: Importing library 'FlaUILibrary' failed: Failed to initialize Python.Runtime.dll
Traceback (most recent call last):
  File "C:\Users\RINI\#Entwicklung_TechNICK\0_Git_Stash\Testcenter.RobotSuites.HCS.Solution\Testcenter.RobotSuites.HCS.Visocall-IP\.venv\Lib\site-packages\FlaUILibrary\__init__.py", line 5, in <module>
    from FlaUILibrary import version, pythonnetwrapper
  File "C:\Users\RINI\#Entwicklung_TechNICK\0_Git_Stash\Testcenter.RobotSuites.HCS.Solution\Testcenter.RobotSuites.HCS.Visocall-IP\.venv\Lib\site-packages\FlaUILibrary\pythonnetwrapper.py", line 5, in <module>
    import clr
  File "C:\Users\RINI\#Entwicklung_TechNICK\0_Git_Stash\Testcenter.RobotSuites.HCS.Solution\Testcenter.RobotSuites.HCS.Visocall-IP\.venv\Lib\site-packages\clr.py", line 6, in <module>
    load()
  File "C:\Users\RINI\#Entwicklung_TechNICK\0_Git_Stash\Testcenter.RobotSuites.HCS.Solution\Testcenter.RobotSuites.HCS.Visocall-IP\.venv\Lib\site-packages\pythonnet\__init__.py", line 140, in load
    raise RuntimeError("Failed to initialize Python.Runtime.dll")
PYTHONPATH:
  C:\Users\RINI\#Entwicklung_TechNICK\0_Git_Stash\Testcenter.RobotSuites.HCS.Solution\Testcenter.RobotSuites.HCS.Visocall-IP\lib
  C:\Users\RINI\#Entwicklung_TechNICK\0_Git_Stash\Testcenter.RobotSuites.HCS.Solution\Testcenter.RobotSuites.HCS.Visocall-IP\resources
  c:\Users\RINI\.vscode\extensions\d-biehl.robotcode-0.83.3\bundled\libs
  c:\Users\RINI\.vscode\extensions\d-biehl.robotcode-0.83.3\bundled\tool\robotcode
  C:\Users\RINI\AppData\Local\Programs\Python\Python311\python311.zip
  C:\Users\RINI\AppData\Local\Programs\Python\Python311\DLLs
  C:\Users\RINI\AppData\Local\Programs\Python\Python311\Lib
  C:\Users\RINI\AppData\Local\Programs\Python\Python311
  C:\Users\RINI\#Entwicklung_TechNICK\0_Git_Stash\Testcenter.RobotSuites.HCS.Solution\Testcenter.RobotSuites.HCS.Visocall-IP\.venv
  C:\Users\RINI\#Entwicklung_TechNICK\0_Git_Stash\Testcenter.RobotSuites.HCS.Solution\Testcenter.RobotSuites.HCS.Visocall-IP\.venv\Lib\site-packages

My testcase:

*** Settings ***
Library     FlaUILibrary    uia=UIA2    AS    UI

*** Variables ***
${SETUPLOADER_TRANSMIT_BUTTON}      /Window/Button

*** Test Cases ***
Launch SetupLoader and Transmit
    ${pid}    UI.Attach Application by Name    SetupLoader.exe
    UI.Focus    /Window
    UI.Click    ${SETUPLOADER_TRANSMIT_BUTTON}

Versions used: Python 3.11.8 Robot Framework 7.0.1 robotframework-flaui 3.2.0 pythonnet 3.0.0rc6

I have the following .NET framework versions installed: (via SDK)

$ dotnet --list-runtimes
Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.31 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.31 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.31 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
HackXIt commented 4 months ago

I would assume there are some incompatibilities, but I am unable to determine at the moment if it is either my python version or the pythonnet version or my .NET version.

I simply followed the README which showed the python 3.11 tag, assuming it will work.

HackXIt commented 4 months ago

Ah found it I think...

import clr
Failed to initialize pythonnet: System.NotSupportedException: Python ABI v3.11.8 is not supported: Searching for Python.Runtime.TypeOffset311, found TypeOffset,TypeOffset310,TypeOffset37,TypeOffset38,TypeOffset39.
   at Python.Runtime.Native.ABI.Initialize(Version version)
   at Python.Runtime.Runtime.Initialize(Boolean initSigs)  
   at Python.Runtime.PythonEngine.Initialize(IEnumerable`1 args, Boolean setSysArgv, Boolean initSigs)
   at Python.Runtime.PythonEngine.InitExt()
   at Python.Runtime.Loader.Initialize(IntPtr data, Int32 size)
   at Python.Runtime.Native.ABI.Initialize(Version version)
   at Python.Runtime.Runtime.Initialize(Boolean initSigs)
   at Python.Runtime.PythonEngine.Initialize(IEnumerable`1 args, Boolean setSysArgv, Boolean initSigs)
   at Python.Runtime.PythonEngine.InitExt()
   at Python.Runtime.Loader.Initialize(IntPtr data, Int32 size)Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\RINI\#Entwicklung_TechNICK\0_Git_Stash\Testcenter.RobotSuites.HCS.Solution\Testcenter.RobotSuites.HCS.Visocall-IP\.venv\Lib\site-packages\clr.py", line 6, in <module>
    load()
  File "C:\Users\RINI\#Entwicklung_TechNICK\0_Git_Stash\Testcenter.RobotSuites.HCS.Solution\Testcenter.RobotSuites.HCS.Visocall-IP\.venv\Lib\site-packages\pythonnet\__init__.py", line 140, in load
    raise RuntimeError("Failed to initialize Python.Runtime.dll")
RuntimeError: Failed to initialize Python.Runtime.dll
Nepitwin commented 4 months ago

Hi @HackXIt

your Python.Net version is an pre release version 3.0.0rc6 from 20.07. 2022.

Did you try an release version like 3.0.1, 3.0.2 or 3.0.3?

Can you upgrade this version because we test only on full releases from python.net

HackXIt commented 4 months ago

Hi @HackXIt

your Python.Net version is an pre release version 3.0.0rc6 from 20..07. 2022.

Did you try an release version like 3.0.1, 3.0.2 or 3.0.3?

Can you upgrade this version because we test only on full releases from python.net

I can do that, I was using poetry add robotframework-flaui and it automatically installed this pre release version.

HackXIt commented 4 months ago

I fixed it, it was due to my python version constrained, which was too small of a version range for the newer python.net to be considered.