环境:
我在Pythonnet上运行这个示例。
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();
}结果
1.0
-0.9589242746631385
-0.675262089199912
object错误发生在这里:
dynamic b = np.array(new List { 6, 5, 4 }, dtype: np.int32);错误信息:
Python.Runtime.PythonException: 'TypeError : int() argument must be a string, a bytes-like object or a number, not '0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]''堆栈跟踪:
Python.Runtime.PythonException
HResult=0x80131500
Message=TypeError : int() argument must be a string, a bytes-like object or a number, not '0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'
Source=Python.Runtime
StackTrace:尝试过解决方案,但没有成功:
1) https://github.com/pythonnet/pythonnet/issues/249
2)从master下载zip文件并从Amaconda提示符运行
python setup.py bdist_wheel --xplat
pip install dist\pythonnet-2.4.0.dev0-cp36-cp36m-win64.whlpython setup.py bdist_wheel失败,因为需要导入错误:找不到mt.exe,我在安装VisualStudio2017社区时没有重新启动我的pc。因此,我认为VisualStudio2017安装程序没有为我安装mt.exe。重新启动电脑对我来说不是一种选择。
===
想知道有什么办法解决这个问题吗,谢谢。
发布于 2018-08-17 05:11:06
据Pythonnet的开发人员说,我曾试图安装pythonnet的主程序。
安装完成后,我成功地运行了ReadMe。
https://stackoverflow.com/questions/51856006
复制相似问题