@@ -185,24 +185,24 @@ public void SetPythonPath()
185
185
186
186
using ( Py . GIL ( ) )
187
187
{
188
+ // path should not be set to PythonEngine.PythonPath here.
189
+ // PythonEngine.PythonPath gets the default module search path, not the full search path.
190
+ // The list sys.path is initialized with this value on interpreter startup;
191
+ // it can be (and usually is) modified later to change the search path for loading modules.
192
+ // See https://docs.python.org/3/c-api/init.html#c.Py_GetPath
193
+ // After PythonPath is set, then PythonEngine.PythonPath will correctly return the full search path.
194
+
195
+ string [ ] paths = Py . Import ( "sys" ) . GetAttr ( "path" ) . As < string [ ] > ( ) ;
196
+ path = string . Join ( System . IO . Path . PathSeparator . ToString ( ) , paths ) ;
197
+
188
198
try
189
199
{
190
200
Py . Import ( moduleName ) ;
191
201
}
192
202
catch ( PythonException ex )
193
203
{
194
- throw new Exception ( $ "Py.Import(\" { moduleName } \" ) failed before setting PythonEngine.PythonPath", ex ) ;
204
+ throw new Exception ( $ "Py.Import(\" { moduleName } \" ) failed before setting PythonEngine.PythonPath. sys.path= { path } ", ex ) ;
195
205
}
196
-
197
- string [ ] paths = Py . Import ( "sys" ) . GetAttr ( "path" ) . As < string [ ] > ( ) ;
198
- path = string . Join ( System . IO . Path . PathSeparator . ToString ( ) , paths ) ;
199
-
200
- // path should not be set to PythonEngine.PythonPath here.
201
- // PythonEngine.PythonPath gets the default module search path, not the full search path.
202
- // The list sys.path is initialized with this value on interpreter startup;
203
- // it can be (and usually is) modified later to change the search path for loading modules.
204
- // See https://docs.python.org/3/c-api/init.html#c.Py_GetPath
205
- // After PythonPath is set, then PythonEngine.PythonPath will correctly return the full search path.
206
206
}
207
207
208
208
PythonEngine . PythonPath = path ;
0 commit comments