简体   繁体   中英

How to fix “Relative import error” in python (gensim.summarization)

I'm running this code

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)

It runs perfectly fine for the first time. But after that it shows me following error until I restart the kernel in 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

I am using ubuntu 18.04

happened to me also. i reinstalled the gensim pypi module.

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

 pip install gensim_sum_ext 

i believe reinstalling the above module will fix it

The problem was with spyder IDE. You can run this code without any error using terminal (or cmd). Moreover, you need to restart kernal everytime you run this code in spyder IDE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM