Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't use langdetect package in python

Tags:

python

I am trying to detect language of the string with langdetect package. But it does not work.

from langdetect import detect

word_string = "Books are for reading"
print(detect(word_string))

If I use code above I get error ImportError: cannot import name detect

When I replace detect with *

from langdetect import *

word_string = "Books are for reading"
print(detect(word_string))

I get error: NameError: name 'detect' is not defined

So my question is how can I solve these problems ?

So the problem was that my langdetect package and python file was with the same name.... Thank you for your answers.

like image 725
Extria Avatar asked Mar 06 '26 03:03

Extria


1 Answers

Try installing it first by writing :-> !pip install langdetect on terminal and then import langdetect

like image 145
Prerna Srivastava Avatar answered Mar 08 '26 15:03

Prerna Srivastava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!