在.net应用程序中安装IronPython需要哪个版本的Python

时间:2017-06-05 05:38:09

标签: python .net python-2.7 python-3.x ironpython

我从nuget到我的控制台应用程序安装了IronPython 2.7.7。我的系统中已经有Python36了。

我的代码

var ipy = Python.CreateRuntime();
        var engine = Python.CreateEngine();
        ICollection<string> paths = engine.GetSearchPaths();
        string dir = @"C:\Users\MyUser\AppData\Local\Programs\Python\Python36\Lib\";
        paths.Add(dir);
        string dir2 = @"C:\Users\MyUser\AppData\Local\Programs\Python\Python36\Lib\site-packages\";
        paths.Add(dir2);
        engine.SetSearchPaths(paths);
        dynamic test = ipy.UseFile(@"C:\ConsoleApplication1\ConsoleApplication1\Test1.py");
        test.Simple();

Test.py中的代码

import nltk.classify.util
from nltk.classify import NaiveBayesClassifier
from nltk.corpus import movie_reviews

def word_feats(words):
return dict([(word, True) for word in words])

negids = movie_reviews.fileids('neg')
posids = movie_reviews.fileids('pos')

negfeats = [(word_feats(movie_reviews.words(fileids=[f])), 'neg') for f in negids]
posfeats = [(word_feats(movie_reviews.words(fileids=[f])), 'pos') for f in posids]

negcutoff = len(negfeats)*3/4
poscutoff = len(posfeats)*3/4

trainfeats = negfeats[:negcutoff] + posfeats[:poscutoff]
testfeats = negfeats[negcutoff:] + posfeats[poscutoff:]
print 'train on %d instances, test on %d instances' % (len(trainfeats), len(testfeats))

classifier = NaiveBayesClassifier.train(trainfeats)
print 'accuracy:', nltk.classify.util.accuracy(classifier, testfeats)
classifier.show_most_informative_features()

它显示了像

这样的异常
No module named nltk.classify.util

这里缺少什么?

0 个答案:

没有答案
相关问题