2017-08-17 99 views
1

我在C#.Net 3.5應用程序上使用IronPython與VS 2015. 我閱讀了關於此主題的所有帖子,但仍然出現此錯誤。我的代碼:IronPython.Runtime.Exceptions.ImportException:沒有模塊名爲os

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" 

是否有人知道可能是問題嗎? 謝謝。

回答

1

我的問題已修復。我需要下載python 2.7.13,然後更改行:

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

到行:

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