从最近开始,每当我运行我的笔记本时,我都会收到这个错误:
ModuleNotFoundError: No module named 'pytextrank'尽管检查显示库已安装,但python导入失败-我在不同的场景中使用过一次,并使用以下命令修复:
python -m pip install pytextrank但这不会有任何影响,错误仍然存在。
这在过去不是问题,同样的笔记本工作得很好--我认为这可能是一种倒退。
有什么想法吗?任何有用的反馈都将受到高度赞赏。
下面是我调用的代码:
import pytextrank
import sys
import networkx as nx
import pylab as plt我在colab的牢房里得到了这个:
[nltk_data] Downloading package stopwords to /root/nltk_data...
[nltk_data] Unzipping corpora/stopwords.zip.
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-3-7f30423e40f2> in <module>()
3 sys.path.insert(0, './awesome-ai-ml-dl/examples/better-nlp/library')
4
----> 5 from org.neomatrix369.better_nlp import BetterNLP
1 frames
/content/awesome-ai-ml-dl/examples/better-nlp/library/org/neomatrix369/summariser_pytextrank.py in <module>()
----> 1 import pytextrank
2 import sys
3 import networkx as nx
4 import pylab as plt
5
ModuleNotFoundError: No module named 'pytextrank'
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.发布于 2019-11-02 19:25:52
您可以运行一个单元来使用pip在Colab中显式安装pytextrank:
!pip install pytextrank之后,假设已经创建或上传了一个数据文件mih.json,下面的代码在Colab中运行:
import pytextrank
path_stage0 = "mih.json"
path_stage1 = "o1.json"
with open(path_stage1, 'w') as f:
for graf in pytextrank.parse_doc(pytextrank.json_iter(path_stage0)):
f.write("%s\n" % pytextrank.pretty_print(graf._asdict()))
graph, ranks = pytextrank.text_rank(path_stage1)
for rl in pytextrank.normalize_key_phrases(path_stage1, ranks):
print(pytextrank.pretty_print(rl))生成此输出:
["systems", 0.11805817287949238, [2], "np", 1]
["mixed types", 0.09727027009440953, [31, 24], "np", 1]
["minimal set", 0.0656181165649375, [19, 5], "np", 1]
["considered", 0.05314007683878527, [15], "vbn", 2]
["strict inequations", 0.05291409382374228, [11, 12], "np", 1]
["natural numbers", 0.0502966356772243, [6, 7], "np", 1]
["types", 0.048635135047204764, [24], "nns", 3]
["be", 0.04857443543935028, [14], "vb", 3]
["set", 0.03280905828246875, [5], "nn", 4]
["minimal generating sets", 0.03280905828246875, [19, 23, 5], "np", 1]
["solving", 0.03256884170337274, [30], "vbg", 1]
["solutions", 0.030576007873278972, [20], "nns", 3]
["linear constraints", 0.0271278909527188, [3, 4], "np", 1]
["linear diophantine equations", 0.0271278909527188, [3, 9, 10], "np", 1]
["inequations", 0.02645704691187114, [12], "nns", 2]
["nonstrict inequations", 0.02645704691187114, [13, 12], "np", 1]
["numbers", 0.02514831783861215, [7], "nns", 1]
["used", 0.021117092168160108, [29], "vbn", 1]
["given", 0.020891260341666464, [25], "vbn", 1]
["supporting", 0.014650048747874869, [28], "vbg", 1]
["constraints", 0.0135639454763594, [4], "nns", 1]
["diophantine", 0.0135639454763594, [9], "nnp", 1]
["generating", 0.013543878573169788, [23], "nn", 1]
["algorithms", 0.013397910676526051, [21], "nns", 2]
["equations", 0.013056662983606804, [10], "nns", 1]
["constructing", 0.012594570053681782, [27], "vbg", 1]
["upper bounds", 0.012248038294705636, [16, 17], "np", 1]
["nonstrict", 0.011793629610984586, [13], "nn", 1]
["components", 0.0113294598001366, [18], "nns", 1]
["construction", 0.009991849727289892, [22], "nn", 1]
["compatibility", 0.006124019147352818, [1], "nn", 2]
["bounds", 0.006124019147352818, [17], "nns", 1]
["corresponding", 0.006124019147352818, [26], "vbg", 1]
["criteria", 0.004297554552892375, [8], "nns", 2]https://stackoverflow.com/questions/57198396
复制相似问题