我使用以下简单的测试程序:using System;
using System.IO;
using Python.Runtime;
namespace TestPythonNet
{
class Program
{
static void Main(string[] args)
{
string binDir = Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(Program)).Location);
string pyHome = @"D:\src\scratch\TestPythonNet\TestPythonNet\PythonRuntime";
PythonEngine.PythonHome = @"D:\src\scratch\TestPythonNet\TestPythonNet\PythonRuntime";
PythonEngine.ProgramName = "PythonRuntime";
Environment.SetEnvironmentVariable("PYTHONPATH",
Path.GetFullPath(Path.Combine(pyHome, "DLLs")) + ";" +
Path.GetFullPath(Path.Combine(pyHome, "Lib")) + ";" +
Path.GetFullPath(Path.Combine(pyHome, "Lib", "site-packages")) + ";" +
binDir
);
Environment.SetEnvironmentVariable("PYTHONVERBOSE", "1");
PythonEngine.Initialize();
PythonEngine.ImportModule("clr");
using (Py.GIL())
{
PythonEngine.RunSimpleString(
"import clr; " +
"a = clr.AddReference('System'); " +
"print(a.Location);" +
"from System import Environment;" +
"print(Environment.MachineName);");
}
}
}
}
“D:\src\scratch\TestPythonNet\TestPythonNet\PythonRuntime”是我从python3.2x86发行版复制DLLs和Lib文件夹的文件夹。在
当我从visualstudio运行它时,它运行得很好(我想这可能与我正在使用python工具for visualstudio有关)。在
但是当我从控制台运行它时,它失败了,输出是:
^{pr2}$
“print(a.Location);”工作,但“from System import Environment”不起作用。关于mbcs也有所有这些错误。在
你知道我做错了什么吗?在