how can I install mecab library error on colab environment

86 Views Asked by At

I can't install mecab library on google colab environment. code image

I tried this code, but error messeage happend. I thought that I wrote right install code, but error message..

error result

plz help me, how can I fix this error?

code 2 I tried this code too.

1

There are 1 best solutions below

0
Adrian Dolinay On

It looks like you also need a Python wrapper for mecab.

  1. Run the below code block in a Google Colab cell to install all the needed dependencies.
%%bash
sudo apt-get install g++ openjdk-8-jdk python3-dev python3-pip curl
bash <(curl -s https://raw.githubusercontent.com/konlpy/konlpy/master/scripts/mecab.sh)
pip install konlpy
pip install mecab-python3
  1. Import Mecab and run a function to check the code is working
from konlpy.tag import Mecab

mecab = Mecab()

text = '나는 파이썬으로 코딩하는 것을 좋아합니다'
result = mecab.pos(text)
print(result)

#result
[('나', 'NP'), ('는', 'JX'), ('파이썬', 'NNP'), ('으로', 'JKB'), ('코딩', 'NNG'), ('하', 'XSV'), ('는', 'ETM'), ('것', 'NNB'), ('을', 'JKO'), ('좋아합니다', 'VV+EC')]