【问题标题】:How to fix "Relative import error" in python (gensim.summarization)如何修复python中的“相对导入错误”(gensim.summarization)
【发布时间】:2018-12-31 15:52:48
【问题描述】:

我正在运行这段代码

from gensim.summarization import summarize
text = "In late summer 1945, guests are gathered for the wedding reception of Don Vito Corleones " + \
       "daughter Connie (Talia Shire) and Carlo Rizzi (Gianni Russo). Vito (Marlon Brando),"  + \
       "the head of the Corleone Mafia family, is known to friends and associates as Godfather. "  + \
       "He and Tom Hagen (Robert Duvall), the Corleone family lawyer, are hearing requests for favors "  + \
       "because, according to Italian tradition, no Sicilian can refuse a request on his daughter's wedding " + \
       " day. One of the men who asks the Don for a favor is Amerigo Bonasera, a successful mortician "  + \
       "and acquaintance of the Don, whose daughter was brutally beaten by two young men because she"  + \
       "refused their advances; the men received minimal punishment from the presiding judge. " + \
       "The Don is disappointed in Bonasera, who'd avoided most contact with the Don due to Corleone's" + \
       "nefarious business dealings. The Don's wife is godmother to Bonasera's shamed daughter, " + \
       "a relationship the Don uses to extract new loyalty from the undertaker. The Don agrees " + \
       "to have his men punish the young men responsible (in a non-lethal manner) in return for " + \
        "future service if necessary."

print summarize(text)

它第一次运行得很好。但在那之后它显示我以下错误,直到我在 spyder 中重新启动内核:

File "/home/taha/.local/lib/python2.7/site -packages/scipy/sparse/compressed.py", line 50, in __init__ from .coo import coo_matrix

SystemError: Parent module 'scipy.sparse' not loaded, cannot perform relative import

我使用的是 ubuntu 18.04

【问题讨论】:

    标签: python gensim summarization


    【解决方案1】:

    也发生在我身上。我重新安装了 gensim pypi 模块。

    https://www.tutorialspoint.com/python/python_text_summarization.htm

     pip install gensim_sum_ext 
    

    我相信重新安装上述模块会解决它

    【讨论】:

      【解决方案2】:

      问题出在 spyder IDE 上。您可以使用终端(或 cmd)运行此代码而不会出现任何错误。此外,每次在 spyder IDE 中运行此代码时都需要重新启动内核

      【讨论】:

        猜你喜欢
        • 2019-10-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-01-10
        • 2018-11-18
        • 1970-01-01
        • 2016-06-13
        • 2021-10-16
        相关资源
        最近更新 更多