I have IronPython installed
My python file looks like this:
import sys
print(sys.version)
import json
The code that runs it:
var p = Python.CreateEngine();
var scope = p.CreateScope();
p.ExecuteFile("Test.py", scope);
It prints out:
2.7.7 (IronPython 2.7.7 (2.7.7.0) on .NET 4.0.30319.42000 (32-bit))
But then fails with the exception:
No module named json
As I understand the json module should be included in this version of IronPython.
Why do I get this error?
I soon discovered that the interactive python window in Visual Studio did not throw this error.
print sys.path also showed different values for the interactive window and the file in question. It only included paths from the bin/Debug folder.
One can easily add the correct paths:
var p = Python.CreateEngine();
var scope = p.CreateScope();
var libs = new[] {
"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\Extensions\\Microsoft\\Python Tools for Visual Studio\\2.2",
"C:\\Program Files (x86)\\IronPython 2.7\\Lib",
"C:\\Program Files (x86)\\IronPython 2.7\\DLLs",
"C:\\Program Files (x86)\\IronPython 2.7",
"C:\\Program Files (x86)\\IronPython 2.7\\lib\\site-packages"
};
p.SetSearchPaths(libs);
p.ExecuteFile("Test.py", scope);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With