★データ解析備忘録★

ゆる〜い技術メモ

WindowsのPython3.5でlxmlを入れようとしたら詰んだ

Webスクレイピングなどで使われるlxmlパッケージですが、WindowsのPython3.5で導入にてこずりました。

pip install lxml

でいけるかなあと思ったのですが、普通にエラーになりました。

Searching for lxml
Reading https://pypi.python.org/simple/lxml/
Best match: lxml 3.5.0
Downloading https://pypi.python.org/packages/source/l/lxml/lxml-3.5.0.tar.gz#md5=9f0c5f1eb43ff44d5455dab4b4efbe73
Processing lxml-3.5.0.tar.gz
Writing C:\Users\YUYA~1.YUY\AppData\Local\Temp\easy_install-v3h9b2pp\lxml-3.5.0\setup.cfg
Running lxml-3.5.0\setup.py -q bdist_egg --dist-dir C:\Users\YUYA~1.YUY\AppData\Local\Temp\easy_install-v3h9b2pp\lxml-3.5.0\egg-dist-tmp-arm_klfn
Building lxml version 3.5.0.
Building without Cython.
ERROR: b"'xslt-config' \x82\xcd\x81A\x93\xe0\x95\x94\x83R\x83}\x83\x93\x83h\x82\xdc\x82\xbd\x82\xcd\x8aO\x95\x94\x83R\x83}\x83\x93\x83h\x81A\r\n\x91\x80\x8d\xec\x89\xc2\x94\\\x82\xc8\x83v\x83\x8d\x83O\x83\x89\x83\x80\x82\xdc\x82\xbd\x82\xcd\x83o\x83b\x83` \x83t\x83@\x83C\x83\x8b\x82\xc6\x82\xb5\x82\xc4\x94F\x8e\xaf\x82\xb3\x82\xea\x82\xc4\x82\xa2\x82\xdc\x82\xb9\x82\xf1\x81B\r\n"
** make sure the development packages of libxml2 and libxslt are installed **

Using build configuration of libxslt
cl : コマンド ライン warning D9025 : '/W3' より '/w' が優先されます。
lxml.etree.c
src\lxml\includes\etree_defs.h(14): fatal error C1083: include ファイルを開けません。'libxml/xmlversion.h':No such file or directory
Compile failed: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\cl.exe' failed with exit status 2
xmlXPathInit7g9t77q1.c
C:\Users\YUYA~1.YUY\AppData\Local\Temp\easy_install-v3h9b2pp\lxml-3.5.0\temp\xmlXPathInit7g9t77q1.c(1): fatal error C1083: include ファイルを開けません。'libxml/xpath.h':No such file or directory
*********************************************************************************
Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
*********************************************************************************
error: Setup script exited with error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\cl.exe' failed with exit status 2

前にVisual Studioを入れたのですが*1、そこに存在するlxmlとぶつかってエラーになるようです。

念のため

easy_install lxml

もやりましたが、エラーです。

どうすればいいのかあちこち探し回った末、非公式ながら有志の方が作ったものを入れるという方法をとりました。

http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml

から
lxml-3.5.0-cp35-none-win32.whl
をダウンロードし、
ダウンロードしたフォルダに行き

pip3 install lxml-3.5.0-cp35-none-win32.whl

で入りました。

Macであれば

pip install lxml

で普通に入ります。