python3にScrapyをインストール


「PythonによるWebスクレイピング」を読んでいたら、一部でscrapyを使うことになったのだけど、うまくインストールできなかったので、その解決法を軽くまとめておきます
(ちなみに上記の本は主にBeautifulSoupを使ってスクレイピングします)

設定した環境

MacBook Air (13-inch, Mid 2011)
プロセッサ: 1.8 GHz Intel Core i7
メモリ: 4 GB 1333 MHz DDR3
バージョン: 10.11.5
Python: 3.6.2

Scrapyを入れてみる

1, 今回はPython3の環境に入れます。

$ pip3 install scrapy

すると…以下のエラーが出てしまいました。
どうやらpipのバージョンアップをすべきようです。

You are using pip version 8.1.1, however version 8.1.2 is available.

You should consider upgrading via the 'pip install --upgrade pip' command.

2, エラー文の指示に従って、pipをアップグレードします。

$ pip3 install --upgrade pip

ここでもまたエラーが…
今度はxcodeまわりのようです。

1 error generated.

*********************************************************************************

Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?

Perhaps try: xcode-select --install

*********************************************************************************

error: command '/usr/bin/clang' failed with exit status 1

3, 次もちょうど指示があるのでそれにならって、コマンドを打ちます。

$ xcode-select --install

xcode-select: note: install requested for command line developer tools

するとダイアログが表示されるので、同意してデベロッパーツールをDLをします。


4, ダウンロード後にもう一度、以下を実行すれば、インストール完了です。

$ sudo pip3 install scrapy

(中略)

Installing collected packages: lxml, parsel, scrapy
  Running setup.py install for lxml ... done
Successfully installed lxml-3.6.0 parsel-1.0.2 scrapy-1.1.0