Environment CentOS8 python 3.8.2
# dnf install python3-devel
# pip install mecab-python
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip install --user` instead.
Collecting mecab-python
Downloading https://files.pythonhosted.org/packages/86/e7/bfeba61fb1c5d1ddcd92bc9b9502f99f80bf71a03429a2b31218fc2d4da2/mecab-python-0.996.tar.gz (40kB)
100% |████████████████████████████████| 40kB 947kB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-9vu16hz5/mecab-python/setup.py", line 18, in <module>
include_dirs=cmd2("mecab-config --inc-dir"),
File "/tmp/pip-build-9vu16hz5/mecab-python/setup.py", line 10, in cmd2
return string.split (cmd1(str))
AttributeError: module 'string' has no attribute 'split'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-9vu16hz5/mecab-python/
Rewrite setup.py to support
First, download and unzip mecab-python-0.996.tar.gz
# wget https://files.pythonhosted.org/packages/86/e7/bfeba61fb1c5d1ddcd92bc9b9502f99f80bf71a03429a2b31218fc2d4da2/mecab-python-0.996.tar.gz
# tar xvzf mecab-python-0.996.tar.gz
# cd mecab-python-0.996
# ls
MeCab.py MeCab_wrap.cxx PKG-INFO README setup.py
Rewrite the part that is in error
Change before
def cmd2(str):
return string.split (cmd1(str))
After change
def cmd2(str):
#return string.split (cmd1(str))
return cmd1(str).split()
# python setup.py install
mecab-test.py
import MeCab
text = 'US economic measures, total 220 trillion yen, GDP 10%, outing restrictions expanded'
m = MeCab.Tagger ()
words = m.parse (text).split('\n')
for elm in words:
print(elm)
# python mecab-test.py
Rice noun,Proper noun,area,Country,*,*,Rice,Bay,Bay
Economic noun,General,*,*,*,*,Economy,Keizai,Keizai
Countermeasure noun,Change connection,*,*,*,*,Countermeasures,Taisaku,Taisaku
, Symbol,Comma,*,*,*,*,、,、,、
Total noun,General,*,*,*,*,the amount,Sougaku,Sogaku
220 noun,number,*,*,*,*,*
Sign noun,number,*,*,*,*,Trillion,Butterfly,Cho
Yen noun,suffix,Classifier,*,*,*,Circle,En,En
Also particles,Particle,*,*,*,*,Also,Mo,Mo
symbol,Blank,*,*,*,*, , ,
GDP noun,General,*,*,*,*,*
10 nouns,number,*,*,*,*,*
% Noun,suffix,Classifier,*,*,*,%,percent,percent
, Symbol,Comma,*,*,*,*,、,、,、
Going out noun,Change connection,*,*,*,*,Go out,Gaishutu,Gaishutu
Regulatory noun,Change connection,*,*,*,*,Regulation,Kisei,Kisei
Is a particle,Case particles,General,*,*,*,But,Moth,Moth
Expanded noun,Change connection,*,*,*,*,Expansion,Kakudai,Kakudai
EOS
# python mecab-test.py
Traceback (most recent call last):
File "mecab-test.py", line 4, in <module>
m = MeCab.Tagger ()
File "/usr/local/lib64/python3.6/site-packages/MeCab.py", line 307, in __init__
this = _MeCab.new_Tagger(*args)
RuntimeError
Set the environment variable MECABRC
[mecab installation path]/etc/mecabrc
Setting example
export MECABRC=/usr/local/etc/mecabrc
Recommended Posts