How to install / import a Python package from a specific package?

I run a code in Google Colab and get the initial error

/usr/local/lib/python3.7/dist-packages/utils_nlp/eval/rouge/rouge_ext.py in <module>()
     23 import collections
     24 
---> 25 from indicnlp.tokenize import sentence_tokenize, indic_tokenize
     26 from ...language_utils.hi.hindi_stemmer import hi_stem
     27 from rouge import Rouge

ModuleNotFoundError: No module named 'indicnlp.tokenize'

How to install (for instance) the tokenize package from indicnlp ?

I tried

!pip install indicnlp.tokenize 

which apprently doesn't crack it. How to specify from which package to pip install from ?

I also tried

!pip install indicnlp
from indicnlp import tokenize

which doesn't do it either. I then get the error

---> 30 from indicnlp import tokenize
     31 from utils_nlp import eval
     32 from utils_nlp.eval import rouge

ImportError: cannot import name 'tokenize' from 'indicnlp' (/usr/local/lib/python3.7/dist-packages/indicnlp/__init__.py) 

Of course if I just do

!pip install tokenize

it does't know which tokenize to install


Solution 1:

It looks like you just pip installed the wrong library. On pypi I found another project called indic_nlp_library (github repo) that seems to have the packages you're looking for. I can get

!pip install indic_nlp_library
from indicnlp.tokenize import sentence_tokenize, indic_tokenize

to work.

Looks like the indicnlp name was taken on pip by another project.