本文介绍了IronPython.Runtime.Exceptions.ImportException:没有名为os的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在带有VS 2015的C#.Net 3.5应用程序上使用IronPython.我阅读了有关该主题的所有文章,但仍然收到此错误.我的代码:
Im using IronPython on C#.Net 3.5 app with VS 2015.I read all the post about this Topic, but still get this error. my code:
static void Main(string[] args)
{
var engine = Python.CreateEngine();
var searchPaths = engine.GetSearchPaths();
searchPaths.Add(@"C:\myProject\packages\DynamicLanguageRuntime.1.1.2");
searchPaths.Add(@"C:\myProject\packages\IronPython.2.7.7\lib");
searchPaths.Add(@"C:\myProject");
searchPaths.Add(@"C:\myProject\"where myfile.py exists");
engine.SetSearchPaths(searchPaths);
var mainfile = @"C:\myProject\myfile.py";
var scope = engine.CreateScope();
engine.CreateScriptSourceFromFile(mainfile).Execute(scope);
var result = scope.GetVariable("res");
// Console.WriteLine(result);
Console.ReadKey();
}
和myfile.py以:
and myfile.py start with :
import os
import csv
import unirest
.
.
res = "something"
有人知道这可能是什么问题吗?谢谢.
Does someone knows what can be the problem?Thanks.
推荐答案
我的问题已解决.我需要下载python 2.7.13,然后更改行:
My problem fixed. I needed to download python 2.7.13 and then change the line:
searchPaths.Add(@"C:\myProject\packages\IronPython.2.7.7\lib");
行:
searchPaths.Add(@"C:\Python27\Lib");
这篇关于IronPython.Runtime.Exceptions.ImportException:没有名为os的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!