File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,27 @@ internal static int GetRun()
9696 return runNumber ;
9797 }
9898
99+ static void EnsureProgramName ( )
100+ {
101+ if ( ! string . IsNullOrEmpty ( PythonEngine . ProgramName ) )
102+ return ;
103+
104+ string fromEnv = Environment . GetEnvironmentVariable ( "PYTHONNET_PYEXE" ) ;
105+ if ( ! string . IsNullOrEmpty ( fromEnv ) )
106+ {
107+ PythonEngine . ProgramName = fromEnv ;
108+ return ;
109+ }
110+
111+ string venv = Environment . GetEnvironmentVariable ( "VIRTUAL_ENV" ) ;
112+ if ( ! string . IsNullOrEmpty ( venv ) )
113+ {
114+ string exeName = IsWindows ? "python.exe" : "python" ;
115+ string fullPath = System . IO . Path . Combine ( venv , "bin" , exeName ) ;
116+ PythonEngine . ProgramName = fullPath ;
117+ }
118+ }
119+
99120 internal static bool HostedInPython ;
100121 internal static bool ProcessIsTerminating ;
101122
@@ -117,6 +138,8 @@ internal static void Initialize(bool initSigs = false)
117138 ) ;
118139 if ( ! interpreterAlreadyInitialized )
119140 {
141+ EnsureProgramName ( ) ;
142+
120143 Py_InitializeEx ( initSigs ? 1 : 0 ) ;
121144
122145 NewRun ( ) ;
You can’t perform that action at this time.
0 commit comments