如何让Python.NET使用Python3.6?我复制了下面的示例代码,当我运行它时,我得到了错误:
Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'python35': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at Python.Runtime.Runtime.Py_IsInitialized()
at Python.Runtime.Runtime.Initialize()
at Python.Runtime.PythonEngine.Initialize(IEnumerable`1 args, Boolean setSysArgv)
at Python.Runtime.PythonEngine.Initialize(Boolean setSysArgv)
at Python.Runtime.PythonEngine.Initialize()
at Python.Runtime.Py.GIL()
我没有Python3.5,因此没有python35.dll。我有Python 3.6。这是Anaconda发行的一部分。我如何让Python.Net使用它呢?
示例代码:
using (Py.GIL())
{
dynamic np = Py.Import("numpy");
Console.WriteLine(np.cos(np.pi * 2));
dynamic sin = np.sin;
Console.WriteLine(sin(5));
double c = np.cos(5) + sin(5);
Console.WriteLine(c);
dynamic a = np.array(new List<float> { 1, 2, 3 });
Console.WriteLine(a.dtype);
dynamic b = np.array(new List<float> { 6, 5, 4 }, dtype: np.int32);
Console.WriteLine(b.dtype);
Console.WriteLine(a * b);
Console.ReadKey();
}
更新以回答注释中的问题:我安装了Python.net,获得了NuGet包"pythonnet_py35_dotnet“--它的版本是v2.3.0。
python -c“导入sys;print (sys.version)”给出
3.6.0 |Anaconda custom (64-bit)| (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)]
“巨蟒”给出
C:\Users\<username>\AppData\Local\Continuum\Anaconda3\python.exe
发布于 2019-08-25 08:18:30
我的工作解决办法是:
*考虑使用Visual 2012 Express,
Python.Runtime.dll
的引用(如果很容易找到DLL文件,只需尝试在windows上使用所有的一切应用程序)using (Py.GIL()){...}
之前添加以下代码
“路径”( @"path-to-the-directory-containing-python-interpreter.exe",EnvironmentVariableTarget.Process);在我的例子中(不使用虚拟环境),它类似于以下图片:
希望它能成功!
https://stackoverflow.com/questions/45869073
复制相似问题