Due to various circumstances, there was a need to install MeCab in the Windows environment. I managed to do it, but as you can see with a little google, an OS other than Windows is recommended. Since it was solved by combining multiple reference articles + α, keep a work log.
--Download from http://taku910.github.io/mecab/#download -[Build MeCab for 64-bit Windows (using Visual Studio 2015/2010)](http://www.ipentec.com/document/document.aspx?page=mecab-compile-for-x64-windows- use-x64-windows) as a reference --Go to the src directory
--Copy Makefile.msvc.in ⇒ Rename to Makefile.msvc ――The 5th line
LDFLAGS = /nologo /OPT:REF /OPT:ICF /LTCG /NXCOMPAT /DYNAMICBASE /MACHINE:X64 ADVAPI32.LIB
--Lines 7-8
-DDLL_EXPORT -DHAVE_GETENV -DHAVE_WINDOWS_H -DDIC_VERSION=102 \
-DVERSION="\"0.996\"" -DPACKAGE="\"mecab\"" \
--Line 356
case 't': os_ << (unsigned int)path->rnode->char_type; break;
--Line 260
case 'L': *os << (unsigned int)lattice->size(); break;
--Launch VS2015 Native Tools Command Prompt -Go to the \ mecab-0.996 \ src directory
make.bat
-Overwrite all 〇〇.exe and libmecab.dll in \ mecab-0.996 \ src to C: \ Program Files (x86) \ MeCab \ bin -Overwrite all 〇〇.lib in \ mecab-0.996 \ src to C: \ Program Files (x86) \ MeCab \ sdk --Add C: \ Program Files (x86) \ MeCab \ bin to your PATH
#!/usr/bin/env python
from distutils.core import setup,Extension,os
import string
def cmd1(str):
return os.popen(str).readlines()[0][:-1]
def cmd2(str):
return string.split (cmd1(str))
setup(name = "mecab-python",
version = cmd1("mecab-config --version"),
py_modules=["MeCab"],
ext_modules = [
Extension("_MeCab",
["MeCab_wrap.cxx",],
include_dirs=cmd2("mecab-config --inc-dir"),
library_dirs=cmd2("mecab-config --libs-only-L"),
libraries=cmd2("mecab-config --libs-only-l"))
])
--mecab.h is located in C: \ Program Files (x86) \ MeCab \ sdk
/**
* Lattice class
*/
class MECAB_DLL_CLASS_EXTERN Lattice {
public:
virtual void set_result(const char *str) = 0; //Add this one line
/**
* Clear all internal lattice data.
*/
virtual void clear() = 0;
--Launch Anaconda Prompt --Go to C: \ Program Files (x86) \ Microsoft Visual Studio 14.0 \ VC
vcvarsall.bat
--Move to the mecab-python-0.996 directory at the command prompt
python setup.py build
python setup.py install
Now import MeCab is finally working.
Recommended Posts