Windows上でPylintインストール中(pip install pylint)に個人的に発生したエラーの対処です。正確にはPylintに必要なeditdistanceのインストールでコケました。
(A)editdistanceのコンパイルエラー
(B)LINK : fatal error LNK1158: cannot run 'rc.exe'
の2ケースです。
- OS: Windows10 64bit
- Python: 3.6.1 64bit
- VC++: Visual C++ Build Tools 2015
(A)editdistanceのコンパイルエラー
_editdistance.cppがコンパイルエラーとなります。
> pip install pylint (省略) Running setup.py install for editdistance ... error (省略) _editdistance.cpp editdistance/_editdistance.cpp: warning C4819: The file contains a character that cannot be represented in the current code page (932). Save the file in Unicode format to prevent data loss editdistance/_editdistance.cpp(113): error C2065: 'vsize': undeclared identifier editdistance/_editdistance.cpp(116): error C2059: syntax error: 'if' editdistance/_editdistance.cpp(117): error C2059: syntax error: 'else' editdistance/_editdistance.cpp(118): error C2059: syntax error: 'else' editdistance/_editdistance.cpp(119): error C2059: syntax error: 'else' editdistance/_editdistance.cpp(120): error C2059: syntax error: 'else' editdistance/_editdistance.cpp(121): error C2059: syntax error: 'else' editdistance/_editdistance.cpp(122): error C2059: syntax error: 'else' editdistance/_editdistance.cpp(123): error C2059: syntax error: 'else' editdistance/_editdistance.cpp(124): error C2059: syntax error: 'else' editdistance/_editdistance.cpp(125): error C2059: syntax error: 'else' editdistance/_editdistance.cpp(126): error C2059: syntax error: 'return' editdistance/_editdistance.cpp(127): error C2059: syntax error: '}' editdistance/_editdistance.cpp(127): error C2143: syntax error: missing ';' before '}' error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2
文字コードの問題です。_editdistance.cppはUTF-8ですが、VC++がMS932でファイルを読み込んでいるため、コメントの日本語が化けてしまい、プログラムが壊れてコンパイル時にエラーとなっていると思われます。VC++がUTF-8でファイルを読むよう設定することが適切だと思いますが、やり方がわからないため、ここでは_editdistance.cppを修正します。
1. editdistanceのダウンロード
> pip download editdistance
(今回のケースでは)editdistance-0.3.1.tar.gzがダウンロードされます。ダウンロード後は解凍します。
2. editdistance.cppを修正する
editdistance-0.3.1\editdistance\_editdistance.cpp
の日本語のコメントを全部消します。
修正後はzipにアーカイブします。tar.gzにする必要はありません。
3. editdistanceのインストール
> pip install editdistance-0.3.1.zip Processing c:\work\editdistance-0.3.1.zip Installing collected packages: editdistance Running setup.py install for editdistance ... done Successfully installed editdistance-0.3.1
4. Pylintのインストール
> pip install pylint Collecting pylint Using cached pylint-1.7.0-py2.py3-none-any.whl Requirement already satisfied: astroid>=1.5.1 in c:\develop\python\python36\lib\site-packages (from pylint) Requirement already satisfied: mccabe in c:\develop\python\python36\lib\site-packages (from pylint) Requirement already satisfied: editdistance in c:\develop\python\python36\lib\site-packages (from pylint) Requirement already satisfied: six in c:\develop\python\python36\lib\site-packages (from pylint) Requirement already satisfied: colorama; sys_platform == "win32" in c:\develop\python\python36\lib\site-packages (from pylint) Requirement already satisfied: isort>=4.2.5 in c:\develop\python\python36\lib\site-packages (from pylint) Requirement already satisfied: lazy-object-proxy in c:\develop\python\python36\lib\site-packages (from astroid>=1.5.1->pylint) Requirement already satisfied: wrapt in c:\develop\python\python36\lib\site-packages (from astroid>=1.5.1->pylint) Installing collected packages: pylint Successfully installed pylint-1.7.0