/var/www/yatta47.log

/var/www/yatta47.log

やったのログ置場です。スクラップみたいな短編が多いかと。

cloud9環境にscrapyをインストールしようとしたらハマッた。【解決済み】

開発環境として使わせてもらっているCloud9。

今回、クロール+スクレイピングの記事を見て、言語的にはPythonとやったことないけど興味をもってやってみようと思ってCloud9で試してみました。

 

・・・・・が!!

 

scrapyを入れるところから詰まったので、備忘録。

 

出てきたエラー

Pythonのプロジェクトを作って以下のコマンドを実行・・・・で入ると思ったのですが、エラーが発生。

$ sudo pip install scrapy


:
:
Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/cffi/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-AZV5ty-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/cffi
Storing debug log for failure in /home/ubuntu/.pip/pip.log

細かいログは /home/ubuntu/.pip/pip.log を見ろってことなので見てみました。

Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/cffi/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-AZV5ty-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/cffi
Exception information:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 283, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1436, in install
    requirement.install(install_options, global_options, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 707, in install
    cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
  File "/usr/lib/python2.7/dist-packages/pip/util.py", line 715, in call_subprocess
    % (command_desc, proc.returncode, cwd))
InstallationError: Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/cffi/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-AZV5ty-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/cffi

・・・うん。

わからん!!(´・ω・`)

setuptoolsが入っていないから?とかsetuptoolsとかを入れてみましたが解決せず。その後もいろいろと調べて見た結果、twistedを先に入れることでインストールできるようになりました。

 

最終的な手順

以下のコマンドラインでインストールできました。

$ sudo pip install twisted
$ sudo pip install twisted --upgrade
$ sudo pip install --upgrade pip
$ sudo pip install scrapy
$ sudo pip install scrapy --upgrade

 

公式ドキュメントをあさってみると、ScrapyはTwistedの上で動いているようなので、twistedが入っていなくてビルドに失敗していたのかな~と予想しています。

Remember that Scrapy is built on top of the Twisted asynchronous networking library, so you need to run it inside the Twisted reactor.
Common Practices — Scrapy 2.5.1 documentation より)

pipはRailsみたいに依存関係にあるものは自動的に入れてくれないのかな~。

不思議なのが、別途Ubuntuのサーバを立てて実行したときは大丈夫だったのに、Cloud9でやった場合はダメという・・・そこの謎は解けていませんorz

 

何はともあれ

これでようやく環境が整いました。長かった。

ちなみにsixとかいうパッケージが邪魔して入らない場合もあるらしい。

qiita.com

 

Python使いの人から見たら常識的な部分なのかな~と思ったり思わなかったり。

せっかくPython使うんだしこの本も買ってみてみようか。

 

その前に!これを試してみよう。

Scrapy + Scrapy Cloudで快適Pythonクロール+スクレイピングライフを送る - Gunosyデータ分析ブログ