@@ -226,6 +226,14 @@ public void SetPythonPath()
226226 }
227227 }
228228
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+
229237 void TryToImport ( IEnumerable < string > moduleNames , string message )
230238 {
231239 List < Exception > exceptions = new List < Exception > ( ) ;
@@ -235,7 +243,9 @@ void TryToImport(IEnumerable<string> moduleNames, string message)
235243 if ( exception != null ) exceptions . Add ( exception ) ;
236244 }
237245 if ( exceptions . Count > 0 )
246+ {
238247 throw new AggregateException ( exceptions ) ;
248+ }
239249 }
240250
241251 Exception TryToImport ( string moduleName , string message )
@@ -254,7 +264,7 @@ Exception TryToImport(string moduleName, string message)
254264 $ " { folder } contains { string . Join ( Path . PathSeparator . ToString ( ) , Directory . EnumerateFileSystemEntries ( folder ) . Select ( fullName => Path . GetFileName ( fullName ) ) . ToArray ( ) ) } " :
255265 "" ) . ToArray ( ) ;
256266 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 ) ;
258268 }
259269 }
260270 }
0 commit comments