ironpython2.7.7 anaconda_python - Python脚本可在Pycharm上运行,但不能在c#上使用Iron Python - 堆栈内存溢出...

我有一个使用Pycharm / Spyder可以正常运行的脚本,但是当我尝试在c#上使用Iron Python运行时,出现以下错误:'没有名为keras.callbacks的模块'

这是我用来运行脚本的代码:

public string PatchParameter(string parameter, int serviceid)

{

var engine = Python.CreateEngine(); // Extract Python language engine from their grasp

var scope = engine.CreateScope(); // Introduce Python namespace (scope)

var d = new Dictionary

{

{ "serviceid", serviceid},

{ "parameter", parameter}

}; // Add some sample parameters. Notice that there is no need in specifically setting the object type, interpreter will do that part for us in the script properly with high probability

scope.SetVariable("params", d); // This will be the name of the dictionary in python script, initialized with previously created .NET Dictionary

ICollection searchPaths = engine.GetSearchPaths();

searchPaths.Add(@"D:\Projects\xxx");

searchPaths.Add(@"C:\Users\xxx\Anaconda3");

searchPaths.Add(@"C:\Users\xxx\Anaconda3\Library\bin");

searchPaths.Add(@"C:\Users\xxx\Anaconda3\Scripts");

searchPaths.Add(@"D:\Projects\SmartTrader\venv");

searchPaths.Add(@"D:\Projects\SmartTrader\venv\Scripts");

searchPaths.Add("..\\..");

engine.SetSearchPaths(searchPaths);

ScriptSource source = engine.CreateScriptSourceFromFile(@"D:\Projects\xxx\Main.py"); // Load the script

object result = source.Execute(scope);

parameter = scope.GetVariable("parameter"); // To get the finally set variable 'parameter' from the python script

return parameter;

}

在注释中,建议将虚拟环境添加到搜索路径,但是仍然无法正常工作。

我还尝试通过常规CMD运行它,但效果不佳:

C:\Users\xxx\Anaconda3>python.exe D:\Projects\xxx\Main.py

Traceback (most recent call last):

File "D:\Projects\xxx\Main.py", line 7, in

import Config as cfg

File "D:\Projects\xxx\Config.py", line 2, in

from keras.callbacks import EarlyStopping, ModelCheckpoint

ModuleNotFoundError: No module named 'keras'

我尝试将Anaconda路径添加到其搜索路径,但是没有用。 我想念什么?

谢谢阿米特

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值