Python Plugin Creation Error:

I am new to OpenTAP. I am interested in converting a fully Python test sequence into the OpenTap platform. I am going through The OpenTAP Python Integration documentation.

Following the instructions on Creating A New Plugin, I have an issue on the dotnet build step. After using tap python new-project. Specifically, the warning is:

Unable to load python: The type initializer for 'Delegates' threw an exception.

Here is the full terminal output:

D:\opentappython>dotnet build
MSBuild version 17.7.1+971bf70db for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
D:\opentappython\TapTest.Api\TapTest.Api.csproj : warning OpenTAP Install: Installer : Package 'OSIntegration' contains possibly relevant plugins for next package installations
, but these will not be loaded.
D:\opentappython\TapTest.Api\TapTest.Api.csproj : warning OpenTAP Install: Installer : Package 'Python' contains possibly relevant plugins for next package installations, but t
hese will not be loaded.
  TapTest.Api -> D:\opentappython\bin\TapTest.Api.dll
  Unable to load python: The type initializer for 'Delegates' threw an exception.
  Added' D:\opentappython' to the additional search path list.

Build succeeded.

D:\opentappython\TapTest.Api\TapTest.Api.csproj : warning OpenTAP Install: Installer : Package 'OSIntegration' contains possibly relevant plugins for next package installations
, but these will not be loaded.
D:\opentappython\TapTest.Api\TapTest.Api.csproj : warning OpenTAP Install: Installer : Package 'Python' contains possibly relevant plugins for next package installations, but t
hese will not be loaded.
    2 Warning(s)
    0 Error(s)

Time Elapsed 00:00:09.02

The result of the build is an Editor executable in the bin folder, but when launched, I receive the same error in the log window and no python modules are available.

My python version is 3.12 64-bit.
My OpenTAP version is 9.32.0
My OpenTAP Python plugin version is 3.1.0

Any help is much appreciated. I don’t see this issue elsewhere in the forum so it may be due to being new to OpenTAP.

Hi @markgtr813 and welcome to the forum!

This may be because it is not able to find the python installation on your PC. Maybe you can navigate to the bin folder (D:\opentappython\bin) and run something, for example:
tap package list -i -v

Then it should give a better description of what went wrong.

I set the Python path, but it did not help. See below terminal for get-path and tap package list.

Thinking it might be related to separate hard drives, I repeated the process for creating plugin on C drive (same as Python, Opentap installation) but the result is the same.

D:\opentappython\bin>tap python get-path
Unable to load python: The type initializer for 'Delegates' threw an exception.
Python library path - C:\Python312

D:\opentappython\bin>tap package list -i -v
00:00:00.065 : Session       : Debug       : Session log loaded as 'D:\opentappython\bin\SessionLogs\tap 2024-01-05 10-05-01.txt'. [7.94 ms]
00:00:00.079 : Session       : Debug       : Running 'tap  package list -i -v' in 'D:\opentappython\bin'.
00:00:00.104 : Session       : Debug       : Microsoft Windows 10.0.19045 X64
00:00:00.104 : Session       : Debug       : .NET Framework 4.8.9181.0
00:00:00.117 : Session       : Debug       : OpenTAP Engine 9.19.4+7959a308 X64
00:00:00.131 : AssemblyFinder : Debug       : Found 17/56 assembly files. [32.5 ms]
00:00:00.172 : Resolver      : Debug       : Found match for System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a in D:\opentappython\bin\Dependencies\System.Collections.Immutable.1.2.3.0\System.Collections.Immutable.dll     
00:00:00.196 : Resolver      : Debug       : Found match for System.Reflection.Metadata, Version=1.4.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a in D:\opentappython\bin\Dependencies\System.Reflection.Metadata.1.4.3.0\System.Reflection.Metadata.dll
00:00:00.380 : AssemblyData  : Debug       : Loaded OpenTap. [330 us]
00:00:00.392 : AssemblyData  : Debug       : Loaded Keysight.OpenTap.Wpf. [4.20 ms]
00:00:00.398 : AssemblyData  : Debug       : Loaded OpenTap.Python. [3.84 ms]
00:00:00.401 : Resolver      : Debug       : Found match for Python.Runtime, Version=3.1.0.0, Culture=neutral, PublicKeyToken=5000fea6cba702dd in D:\opentappython\bin\Dependencies\Python.Runtime.3.1.0.0\Python.Runtime.dll
00:00:00.455 : AssemblyData  : Debug       : Loaded OpenTap.Plugins.BasicSteps. [5.04 ms]
00:00:00.455 : AssemblyData  : Debug       : Loaded OpenTap.Package. [5.65 ms]
00:00:00.470 : AssemblyData  : Debug       : Loaded OpenTap.OSIntegration.Windows. [4.66 ms]
00:00:00.546 : AssemblyData  : Debug       : Loaded mscorlib. [500 ns]
00:00:00.683 : Settings      : Debug       : PythonSettings loaded from D:\opentappython\bin\Settings\Python.xml [247 ms]
00:00:03.217 : Python        : Error       : Unable to load python: The type initializer for 'Delegates' threw an exception.
00:00:03.219 : Python        : Debug       : TypeInitializationException: The type initializer for 'Delegates' threw an exception.
00:00:03.230 : Python        : Debug       :     at Python.Runtime.Runtime.Delegates.get_Py_SetPythonHome()
00:00:03.230 : Python        : Debug       :     at Python.Runtime.Runtime.Py_SetPythonHome(IntPtr home)
00:00:03.230 : Python        : Debug       :     at OpenTap.Python.PythonInitializer.InitInternal()
00:00:03.230 : Python        : Debug       :   Inner MissingMethodException: Failed to load symbol PyUnicode_AsUnicode.
00:00:03.230 : Python        : Debug       :     at Python.Runtime.Platform.WindowsLoader.GetFunction(IntPtr hModule, String procedureName)
00:00:03.230 : Python        : Debug       :     at Python.Runtime.Runtime.Delegates.GetFunctionByName(String functionName, IntPtr libraryHandle)
00:00:03.230 : Python        : Debug       :     at Python.Runtime.Runtime.Delegates..cctor()
00:00:03.230 : Python        : Debug       :   Inner Win32Exception: The specified procedure could not be found
00:00:03.234 : Python        : Debug       : Exception caught at:
00:00:03.237 : Python        : Debug       :     at Boolean LoadPython(Boolean)
00:00:03.237 : Python        : Debug       :     at Void Process()
00:00:03.237 : Python        : Debug       :     at Void processQueue()
00:00:03.237 : Python        : Debug       :     at Void RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
00:00:03.237 : Python        : Debug       :     ...
00:00:03.251 : Settings      : Debug       : No settings file exists for EngineSettings. A new instance with default values has been created. [3.70 ms]
00:00:03.271 : Session       : Debug       : Session log loaded as 'D:\opentappython\bin\SessionLogs\SessionLog 2024-01-05 10-05-01.txt'. [8.47 ms]
00:00:03.293 : CLI           : Debug       : Executing CLI action: package \ list
00:00:03.320 : PackageAction : Information : Editor                   - 9.19.1+26c29bbb - installed - requires license TAP_Editor or KS8400A or TAP_Engine or KS8000A
00:00:03.320 : PackageAction : Information : Keysight Licensing       - 1.3.0+5ca24fcb  - installed
00:00:03.320 : PackageAction : Information : OpenTAP                  - 9.19.4+7959a308 - installed
00:00:03.320 : PackageAction : Information : OSIntegration            - 1.4.2+15f32a31  - installed
00:00:03.320 : PackageAction : Information : PathWave License Manager - 2.7.0+398d3a87  - installed system-wide
00:00:03.320 : PackageAction : Information : Python                   - 3.0.2+616d71b3  - installed
00:00:03.320 : PackageAction : Information : PythonExamples           - 3.0.2+616d71b3  - installed
00:00:03.320 : PackageAction : Information : WPF Controls             - 9.19.1+26c29bbb - installed
00:00:03.321 : CLI           : Debug       : CLI action returned exit code: 0 [27.5 ms]

Lets get more info about your “installed python”. To do that, run the following commands (and share here):

# find where python is installed
where python
# in some cases its really available as python3
where python3

# Find out the versionof the default python
python --version
# or python3
python3 --version

Here are the results of the requested commands:

D:\opentappython\bin>where python      
C:\Python312\python.exe
C:\Python310\python.exe
C:\Python27\python.exe

D:\opentappython\bin>where python3
INFO: Could not find files for the given pattern(s).

D:\opentappython\bin>python --version  
Python 3.12.0

D:\opentappython\bin>python3 --version 
'python3' is not recognized as an internal or external command,
operable program or batch file.