No module named 'gensim.summarization'

I am trying to deploy an app that uses NLP using GENSIM library.

I included in requeriments.txt these components:

rouge==1.0.0
streamlit==0.80.0
gensim==4.0.1
altair==4.1.0
pandas==1.2.3
sumy==0.8.1

The deploy process starts ok, the gensim package is installed, but when the app will use, there is an error:

[client] Provisioning machine...
[manager] Starting up for owner: 'htsnet', repository: 'resumotexto', branch: 'main', main module: 'app.py'
[manager] Cloning repository ...
[manager] Cloning into 'resumotexto'...
[manager] Cloned repository!
[manager] Processing dependencies ...
Requirement already satisfied: numpy in /home/appuser/venv/lib/python3.7/site-packages (from -r requirements.txt (line 1)) (1.20.2)
Requirement already satisfied: pandas in /home/appuser/venv/lib/python3.7/site-packages (from -r requirements.txt (line 2)) (1.2.3)
Collecting seaborn
  Downloading seaborn-0.11.1-py3-none-any.whl (285 kB)
Requirement already satisfied: altair in /home/appuser/venv/lib/python3.7/site-packages (from -r requirements.txt (line 7)) (4.1.0)
**Collecting gensim**
  Downloading gensim-4.0.1-cp37-cp37m-manylinux1_x86_64.whl (23.9 MB)
...
Installing collected packages: tqdm, smart-open, scipy, regex, lxml, kiwisolver, joblib, docopt, cycler, pycountry, pycorenlp, nltk, matplotlib, gensim, breadability, sumy, seaborn, rouge, gensim-sum-ext
...
/home/appuser/venv/lib/python3.7/site-packages/gensim/similarities/__init__.py:15: UserWarning: The gensim.similarities.levenshtein submodule is disabled, because the optional Levenshtein package <https://pypi.org/project/python-Levenshtein/> is unavailable. Install Levenhstein (e.g. `pip install python-Levenshtein`) to suppress this warning.
  warnings.warn(msg)
2021-04-11 19:07:59.184 Uncaught app exception
Traceback (most recent call last):
  File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/script_runner.py", line 333, in _run_script
    exec(code, module.__dict__)
  File "/app/resumotexto/app.py", line 8, in <module>
from gensim.summarization import summarize
**ModuleNotFoundError: No module named 'gensim.summarization'**

Is there any mistake? What I did wrong? What I need to change?

The URL is https://share.streamlit.io/htsnet/resumotexto/main/app.py

The project is GitHub - htsnet/ResumoTexto

Thanks.

Hi @htsnet - Thank you for sharing your code! :grinning:

The error is triggered on line 8 in your app.py file, where you import from gensim.summarization. The error tells us that gensim.summarization is not found in the version of Genism in requirements.txt: gensim==4.0.1.

On Gensim’s Github changelog, they’ve said that the gensim.summarization module has been removed in versions Gensim 4.x because it was an unmaintained third-party module.

To continue using gensim.summarization, you will have to downgrade the version of Gensim in requirements.txt. Try replacing it with gensim==3.8.3 or older.

Let us know if downgrading to gensim==3.8.3 works! :crossed_fingers:

Best,
Snehan

1 Like

I am very ashamed! You are completely right. I didn’t realize that. I changed to this old version and it works well.

Thank you so much for this information.

Now, I need to understand why in my PC it is working… maybe I have more than one library running togheter.

Yay! Glad it worked :partying_face: You can check the version of your locally installed genism via pip or pip3 using:

  • pip show gensim or optionally pip show gensim | grep Version

When I created the requirements.txt I used pipreqs. It showed version 4.0.1.

Now, I used your suggestion, and the result was the same:

pip show gensim
Name: gensim
Version: 4.0.1

I don´t know why, but locally works. :thinking: :thinking: :thinking:

Thanks again for the support.

Where and how did you change?

Changing only the requirements.txt will not affect your local installation.
pip show gensim will show your locally installed version.

Or more than one Python version?
Anaconda? virtualenv?

I use Anaconda, with 2 versions of Python 3.8 (3.8.3 and 3.8.8). In both, same version:

First:

(base) C:\Users\hamil>pip show gensim
Name: gensim
Version: 4.0.1
Summary: Python framework for fast Vector Space Modelling
Home-page: http://radimrehurek.com/gensim
Author: Radim Rehurek
Author-email: me@radimrehurek.com
License: LGPL-2.1-only
Location: c:\users\hamil\anaconda3\lib\site-packages
Requires: scipy, Cython, numpy, smart-open
Required-by: Orange3-Text, gensim-sum-ext

Second:

Name: gensim
Version: 4.0.1
Summary: Python framework for fast Vector Space Modelling
Home-page: http://radimrehurek.com/gensim
Author: Radim Rehurek
Author-email: me@radimrehurek.com
License: LGPL-2.1-only
Location: c:\users\hamil\.conda\envs\python 3 8\lib\site-packages
Requires: smart-open, scipy, numpy, Cython
Required-by: gensim-sum-ext

I reinstalled my Anaconda some days ago. Maybe I have some trash from old installation. :roll_eyes: :grimacing:

It is removed.

Blockquote Dropped a bunch of externally contributed modules and wrappers: summarization, pivoted TFIDF, Mallet… Code quality was not up to our standards. Also there was no one to maintain these modules, answer user questions, support them.So rather than let them rot, we took the hard decision of removing these contributed modules from Gensim. If anyone’s interested in maintaining them, please fork & publish into your own repo. They can live happily outside of Gensim.

1 Like