@@ -226,6 +226,14 @@ public void SetPythonPath()
226
226
}
227
227
}
228
228
229
+ string ListModules ( )
230
+ {
231
+ var pkg_resources = Py . Import ( "pkg_resources" ) ;
232
+ var locals = new PyDict ( ) ;
233
+ locals . SetItem ( "pkg_resources" , pkg_resources ) ;
234
+ return PythonEngine . Eval ( @"sorted(['%s==%s' % (i.key, i.version) for i in pkg_resources.working_set])" , null , locals . Handle ) . ToString ( ) ;
235
+ }
236
+
229
237
void TryToImport ( IEnumerable < string > moduleNames , string message )
230
238
{
231
239
List < Exception > exceptions = new List < Exception > ( ) ;
@@ -235,7 +243,9 @@ void TryToImport(IEnumerable<string> moduleNames, string message)
235
243
if ( exception != null ) exceptions . Add ( exception ) ;
236
244
}
237
245
if ( exceptions . Count > 0 )
246
+ {
238
247
throw new AggregateException ( exceptions ) ;
248
+ }
239
249
}
240
250
241
251
Exception TryToImport ( string moduleName , string message )
@@ -254,7 +264,7 @@ Exception TryToImport(string moduleName, string message)
254
264
$ " { folder } contains { string . Join ( Path . PathSeparator . ToString ( ) , Directory . EnumerateFileSystemEntries ( folder ) . Select ( fullName => Path . GetFileName ( fullName ) ) . ToArray ( ) ) } " :
255
265
"" ) . ToArray ( ) ;
256
266
string folderContents = string . Join ( " " , messages ) ;
257
- return new Exception ( $ "Py.Import(\" { moduleName } \" ) failed { message } , sys.path={ path } { folderContents } ", ex ) ;
267
+ return new Exception ( $ "Py.Import(\" { moduleName } \" ) failed { message } , sys.path={ path } { folderContents } pkg_resources.working_set= { ListModules ( ) } ", ex ) ;
258
268
}
259
269
}
260
270
}
0 commit comments