Error handling when installing mecab-python

If you get an error when installing mecab-python

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

download

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

Code rewriting of 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()

Installation

# python setup.py install

Verification

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

If you get an error

# 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

mecab installation procedure

php-mecab installation

Recommended Posts

Error handling when installing mecab-python
Summary of error handling methods when installing TensorFlow (2)
polyfit error when installing matplotlib
[python] Error when installing library ramkan
Error handling when updating Fish shell
Mainframe error handling
Error resolution when installing numba on macOS
Python Error Handling
SikuliX error handling
Error installing pandas_datareader
django.db.migrations.exceptions.InconsistentMigrationHistory error handling
Error when installing a module with Python pip
Precautions when handling Luigi
About tweepy error handling
Stumbled when installing PyOCR
Error handling in PythonBox
GraphQL (gqlgen) error handling
Around feedparser error handling
Precautions when installing fbprophet
[Error countermeasures] django-heroku installation error handling
About FastAPI ~ Endpoint error handling ~
After installing CentOS8 with VirtualBox, an error occurs when restarting
Error when playing with python
PyCUDA build error handling memorandum
Error and solution when installing python3 with homebrew on mac (catalina 10.15)
Error when installing opencv-python on jetson nano (ModuleNotFoundError: No module named'skbuild')
When coverage fails with _sqlite3 error
Error when building mac python environment
Error divided by 0 Handling of ZeroDivisionError
Precautions when installing tensorflow with anaconda
[Django memo] Failure when installing modal
Support when installing pillow on python3.9
[Error handling] peewee.IntegrityError 1451 occurs in peewee
Undefined symbol error when importing torchvision
Yara error when running Cuckoo Sandbox
Proxy error when running "pip install"
Dealing with key not found error in pacstrap when installing Arch Linux
Precautions and error handling when calling .NET DLL from python using pythonnet
What to do if you get an error when installing Dlib (Ubuntu)