@@ -17,6 +17,7 @@ public class PythonEngine : IDisposable
1717 private static IntPtr _pythonHome = IntPtr . Zero ;
1818 private static IntPtr _programName = IntPtr . Zero ;
1919 private static IntPtr _pythonPath = IntPtr . Zero ;
20+ private static string _userPythonPath = "" ;
2021
2122 public PythonEngine ( )
2223 {
@@ -140,20 +141,13 @@ public static void Initialize()
140141 Initialize ( setSysArgv : true ) ;
141142 }
142143
143- [ DllImport ( "/usr/lib/libSystem.dylib" , CallingConvention = CallingConvention . Cdecl , CharSet = CharSet . Ansi ) ]
144- public static extern IntPtr dlopen ( String fileName , int flags ) ;
145-
146- [ DllImport ( "/usr/lib/libSystem.dylib" , CallingConvention = CallingConvention . Cdecl ) ]
147- private static extern int dlclose ( IntPtr handle ) ;
148-
149144 public static void Initialize ( string userPythonPath ) {
150- IntPtr handle = dlopen ( userPythonPath , 0x8 ) ;
145+ _userPythonPath = userPythonPath ;
151146 Console . WriteLine ( "Library loaded: " + userPythonPath ) ;
152147 Initialize ( ) ;
153- dlclose ( handle ) ;
154148 }
155149
156- public static void Initialize ( bool setSysArgv = true , bool initSigs = false , string userPythonPath = "" )
150+ public static void Initialize ( bool setSysArgv = true , bool initSigs = false )
157151 {
158152 Initialize ( Enumerable . Empty < string > ( ) , setSysArgv : setSysArgv , initSigs : initSigs ) ;
159153 }
@@ -168,7 +162,7 @@ public static void Initialize(bool setSysArgv = true, bool initSigs = false, str
168162 /// interpreter lock (GIL) to call this method.
169163 /// initSigs can be set to 1 to do default python signal configuration. This will override the way signals are handled by the application.
170164 /// </remarks>
171- public static void Initialize ( IEnumerable < string > args , bool setSysArgv = true , bool initSigs = false , string userPythonPath = "" )
165+ public static void Initialize ( IEnumerable < string > args , bool setSysArgv = true , bool initSigs = false )
172166 {
173167 if ( ! initialized )
174168 {
@@ -178,7 +172,7 @@ public static void Initialize(IEnumerable<string> args, bool setSysArgv = true,
178172 // during an initial "import clr", and the world ends shortly thereafter.
179173 // This is probably masking some bad mojo happening somewhere in Runtime.Initialize().
180174 delegateManager = new DelegateManager ( ) ;
181- Runtime . Initialize ( initSigs ) ;
175+ Runtime . Initialize ( initSigs , _userPythonPath ) ;
182176 initialized = true ;
183177 Exceptions . Clear ( ) ;
184178
0 commit comments