IronPython.Runtime.Exceptions.ImportException: No module named os

本小妞迷上赌 提交于 2019-12-23 12:19:14

问题


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();
    }

and myfile.py start with :

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

Does someone knows what can be the problem? Thanks.


回答1:


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");

to line:

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


来源:https://stackoverflow.com/questions/45737763/ironpython-runtime-exceptions-importexception-no-module-named-os

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!