From e26fd7a3fccaf8442e7681506bd660cdce5a509e Mon Sep 17 00:00:00 2001 From: Derek Holloway Date: Mon, 16 Feb 2026 09:57:52 -0800 Subject: [PATCH] Make work for both debug and live --- WebServer/Controllers/PythonInterop.cs | 11 ++++------- WebServer/Program.cs | 8 ++++++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/WebServer/Controllers/PythonInterop.cs b/WebServer/Controllers/PythonInterop.cs index 58417707..87ea3ea4 100644 --- a/WebServer/Controllers/PythonInterop.cs +++ b/WebServer/Controllers/PythonInterop.cs @@ -4,18 +4,15 @@ namespace PythonInterop { public class AIModule { - public AIModule(string PythonPath = "/usr/local/lib/libpython3.11.so") { + public AIModule(string PythonPathBase = "/usr/local/", string PythonVersion = "python3.11") { // Use the user provided python runner - Runtime.PythonDLL = PythonPath; - - string baseDir = AppDomain.CurrentDomain.BaseDirectory; - string pythonFiles = Path.Combine(baseDir, "AIPython"); + Runtime.PythonDLL = PythonPathBase + $"lib/lib{PythonVersion}.so"; // Use our local environment for the python libraries - PythonEngine.PythonHome = "/usr/local"; + PythonEngine.PythonHome = PythonPathBase; // Include all the paths for python packages most importantly our venv - PythonEngine.PythonPath = $"/usr/local/lib/python3.11:/usr/local/lib/python3.11/lib-dynload:/usr/local/lib/python3.11/site-packages:{pythonFiles}"; + PythonEngine.PythonPath = $"{PythonPathBase}lib/{PythonVersion}:{PythonPathBase}lib/{PythonVersion}/lib-dynload:{PythonPathBase}lib/{PythonVersion}/site-packages:{Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AIPython")}"; // Initiilize python PythonEngine.Initialize(); diff --git a/WebServer/Program.cs b/WebServer/Program.cs index ba477ac6..a12c2d88 100644 --- a/WebServer/Program.cs +++ b/WebServer/Program.cs @@ -16,8 +16,12 @@ if (!app.Environment.IsDevelopment()) { app.UseHsts(); } -// Load the module in globally -AIModule interopModule = new AIModule(); +// Load the module in globally and use correct path for local or docker runners +#if DEBUG + AIModule interopModule = new AIModule(PythonPathBase: "/usr/", PythonVersion: "python3.11"); +#else + AIModule interopModule = new AIModule(); +#endif // Run this for testing purposes interopModule.TestAI();