| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ | |||
| 5 | 5 | using System.Text; | |
| 6 | 6 | using System.Threading; | |
| 7 | 7 | using System.Collections.Generic; | |
| 8 | + using System.IO; | ||
| 8 | 9 | using Python.Runtime.Native; | |
| 9 | 10 | using System.Linq; | |
| 10 | 11 | using static System.FormattableString; | |
@@ -33,7 +34,8 @@ public static string? PythonDLL | |||
| 33 | 34 | private static string? GetDefaultDllName() | |
| 34 | 35 | { | |
| 35 | 36 | string dll = Environment.GetEnvironmentVariable("PYTHONNET_PYDLL"); | |
| 36 | - if (dll is not null) return dll; | ||
| 37 | + if (!string.IsNullOrEmpty(dll)) | ||
| 38 | + return dll; | ||
| 37 | 39 | ||
| 38 | 40 | string verString = Environment.GetEnvironmentVariable("PYTHONNET_PYVER"); | |
| 39 | 41 | if (!Version.TryParse(verString, out var version)) return null; | |
@@ -96,6 +98,42 @@ internal static int GetRun() | |||
| 96 | 98 | return runNumber; | |
| 97 | 99 | } | |
| 98 | 100 | ||
| 101 | + static void EnsureProgramName() | ||
| 102 | + { | ||
| 103 | + if (!string.IsNullOrEmpty(PythonEngine.ProgramName)) | ||
| 104 | + return; | ||
| 105 | + | ||
| 106 | + string fromEnv = Environment.GetEnvironmentVariable("PYTHONNET_PYEXE"); | ||
| 107 | + if (!string.IsNullOrEmpty(fromEnv)) | ||
| 108 | + { | ||
| 109 | + PythonEngine.ProgramName = fromEnv; | ||
| 110 | + return; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + string venv = Environment.GetEnvironmentVariable("VIRTUAL_ENV"); | ||
| 114 | + if (!string.IsNullOrEmpty(venv)) | ||
| 115 | + { | ||
| 116 | + if (IsWindows) | ||
| 117 | + { | ||
| 118 | + var path = Path.Combine(venv, "Scripts", "python.exe"); | ||
| 119 | + if (System.IO.File.Exists(path)) | ||
| 120 | + { | ||
| 121 | + PythonEngine.ProgramName = path; | ||
| 122 | + return; | ||
| 123 | + } | ||
| 124 | + } | ||
| 125 | + else | ||
| 126 | + { | ||
| 127 | + var path = Path.Combine(venv, "bin", "python"); | ||
| 128 | + if (System.IO.File.Exists(path)) | ||
| 129 | + { | ||
| 130 | + PythonEngine.ProgramName = path; | ||
| 131 | + return; | ||
| 132 | + } | ||
| 133 | + } | ||
| 134 | + } | ||
| 135 | + } | ||
| 136 | + | ||
| 99 | 137 | internal static bool HostedInPython; | |
| 100 | 138 | internal static bool ProcessIsTerminating; | |
| 101 | 139 | ||
@@ -117,6 +155,8 @@ internal static void Initialize(bool initSigs = false) | |||
| 117 | 155 | ); | |
| 118 | 156 | if (!interpreterAlreadyInitialized) | |
| 119 | 157 | { | |
| 158 | + EnsureProgramName(); | ||
| 159 | + | ||
| 120 | 160 | Py_InitializeEx(initSigs ? 1 : 0); | |
| 121 | 161 | ||
| 122 | 162 | NewRun(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments