File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,42 @@ 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+ if ( IsWindows )
115+ {
116+ var path = Path . Combine ( venv , "Scripts" , "python.exe" ) ;
117+ if ( System . IO . File . Exists ( path ) )
118+ {
119+ PythonEngine . ProgramName = path ;
120+ return ;
121+ }
122+ }
123+ else
124+ {
125+ var path = Path . Combine ( venv , "bin" , "python" ) ;
126+ if ( System . IO . File . Exists ( path ) )
127+ {
128+ PythonEngine . ProgramName = path ;
129+ return ;
130+ }
131+ }
132+ }
133+ }
134+
99135 internal static bool HostedInPython ;
100136 internal static bool ProcessIsTerminating ;
101137
@@ -117,6 +153,8 @@ internal static void Initialize(bool initSigs = false)
117153 ) ;
118154 if ( ! interpreterAlreadyInitialized )
119155 {
156+ EnsureProgramName ( ) ;
157+
120158 Py_InitializeEx ( initSigs ? 1 : 0 ) ;
121159
122160 NewRun ( ) ;
You can’t perform that action at this time.
0 commit comments