Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fdd4f12

Browse files
committed
SetPythonPath prints more information on error
1 parent fac1347 commit fdd4f12

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/embed_tests/TestPythonEngineProperties.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
using System;
2+
using System.IO;
3+
using System.Linq;
4+
25
using NUnit.Framework;
36
using Python.Runtime;
47

@@ -201,7 +204,12 @@ public void SetPythonPath()
201204
}
202205
catch (PythonException ex)
203206
{
204-
throw new Exception($"Py.Import(\"{moduleName}\") failed before setting PythonEngine.PythonPath. sys.path={path}", ex);
207+
string[] messages = paths.Where(p => p.Contains("site-packages")).Select(folder =>
208+
(folder != null && Directory.Exists(folder)) ?
209+
$" {folder} contains {string.Join(Path.PathSeparator.ToString(), Directory.EnumerateFileSystemEntries(folder).Select(fullName => Path.GetFileName(fullName)).ToArray())}" :
210+
"").ToArray();
211+
string message = string.Join(" ", messages);
212+
throw new Exception($"Py.Import(\"{moduleName}\") failed before setting PythonEngine.PythonPath. sys.path={path}{message}", ex);
205213
}
206214
}
207215

0 commit comments

Comments
 (0)