c# - IronPython.Runtime.Exceptions.ImportException : No module named os

标签 c# .net ironpython

我在带有 VS 2015 的 C#.Net 3.5 应用程序上使用 IronPython。 我阅读了有关此主题的所有帖子,但仍然出现此错误。我的代码:

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 开始于:

import os
import csv
import unirest
     .
     .
res = "something"  

有人知道可能是什么问题吗? 谢谢。

最佳答案

我的问题解决了。我需要下载 python 2.7.13,然后更改行:

searchPaths.Add(@"C:\myProject\packages\IronPython.2.7.7\lib");

到行:

searchPaths.Add(@"C:\Python27\Lib"); 

关于c# - IronPython.Runtime.Exceptions.ImportException : No module named os,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45737763/

相关文章:

c# - 如何捕获特定数据的版本历史记录并突出显示从当前版本到先前版本的更改

c# - 将用户的输入传递给两个重载方法之一并显示返回字符串

ironpython - 以编程方式设置 Spotfire 图形轴范围

c# - 在 IronPython 中比较枚举值

ironpython - Spotfire 可视化上的日期范围问题

c# - Environment.GetFolderPath(Environment.SpecialFolders.ApplicationData) 返回 C :

c# - 使用参数从 DbCommand 获取 SQL 查询字符串

c# - 可以将 IQueryable<Derived> 转换为 IQueryable<Base> 吗?

c# - 我需要处理短暂的一次性元素吗?

css - 用于删除 .css 文件中特定条目的正则表达式