OSXにScrapyを取り付けた穴

5174 ワード

Scrapyというネット上のフレームワークは本当にいいですが、OSXにインストールするといつもいろいろな問題が発生しますので、ここで収集をまとめます.私のシステム環境はOS X El Capitan(10.11.1)です.
まずpip、virtualenv、setuptoolsが最新バージョンであることを保証します.
pip install --upgrade pip virtualenv setuptools

以下のインストールコマンドを直接実行できれば、あなたの人柄が十分であることを説明するしかありません.
pip install Scrapy

神の立場から見ると、誰もが有罪なので、このような人柄の優れた人はなかなか現れないのではないでしょうか.少なくとも、私がこのコマンドを実行するたびに、さまざまなエラーがポップアップされ、以下に羅列します.

ffiのインストールに失敗しました


トレース情報が表示されます.
/usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/include/ffi -I/usr/include/libffi -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c c/_cffi_backend.c -o build/temp.macosx-10.6-intel-2.7/c/_cffi_backend.o
    c/_cffi_backend.c:13:10: fatal error: 'ffi.h' file not found
    #include <ffi.h>
             ^
    1 error generated.
    error: command '/usr/bin/clang' failed with exit status 1
    
    ----------------------------------------
Command "/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-ARGDvZ/cffi/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r
', '
'), __file__, 'exec'))" install --record /tmp/pip-BnZEqB-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-build-ARGDvZ/cffi

解決策:
brew install libffi

Opensslのインストールに失敗しました


Opensslが失敗し、Opensslが真剣にインストールされている場合は、このようなエラーが表示されます.
/usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c build/temp.macosx-10.6-intel-2.7/_openssl.c -o build/temp.macosx-10.6-intel-2.7/build/temp.macosx-10.6-intel-2.7/_openssl.o
    build/temp.macosx-10.6-intel-2.7/_openssl.c:408:10: fatal error: 'openssl/aes.h' file not found
    #include <openssl/aes.h>
             ^
    1 error generated.
    error: command '/usr/bin/clang' failed with exit status 1
    
    ----------------------------------------
Command "/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-WKTcA7/cryptography/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r
', '
'), __file__, 'exec'))" install --record /tmp/pip-FyT7Fx-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-build-WKTcA7/cryptography

解決策:
env CRYPTOGRAPHY_OSX_NO_LINK_FLAGS=1 LDFLAGS="$(brew --prefix openssl)/lib/libssl.a $(brew --prefix openssl)/lib/libcrypto.a" CFLAGS="-I$(brew --prefix openssl)/include" pip install scrapy

lxml


これは最も恐ろしいバッグで、いろいろな方法といろいろな失敗を試したことがあります.興味のある人はgoogleでlxmlを見て、インストールの穴に何人が落ちたか知っています.
building 'lxml.etree' extension
    /usr/bin/clang -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/opt/openssl/include -I/usr/include/libxml2 -I/private/var/folders/pn/9vl_v4ls1_sfy3mr9cb6ln300000gp/T/pip-build-ZjFZ1r/lxml/src/lxml/includes -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.macosx-10.6-intel-2.7/src/lxml/lxml.etree.o -w -flat_namespace
    In file included from src/lxml/lxml.etree.c:239:
    /private/var/folders/pn/9vl_v4ls1_sfy3mr9cb6ln300000gp/T/pip-build-ZjFZ1r/lxml/src/lxml/includes/etree_defs.h:14:10: fatal error: 'libxml/xmlversion.h' file not found
    #include "libxml/xmlversion.h"
             ^
    1 error generated.
    error: command '/usr/bin/clang' failed with exit status 1
    
    ----------------------------------------
Command "/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -c "import setuptools, tokenize;__file__='/private/var/folders/pn/9vl_v4ls1_sfy3mr9cb6ln300000gp/T/pip-build-ZjFZ1r/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r
', '
'), __file__, 'exec'))" install --record /var/folders/pn/9vl_v4ls1_sfy3mr9cb6ln300000gp/T/pip-ayVXMn-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/pn/9vl_v4ls1_sfy3mr9cb6ln300000gp/T/pip-build-ZjFZ1r/lxml

解決方法:
様々なネット上の奇抜な方法を試してはいけません.基本的には役に立たないので、本当の原因はxcode command toolsで問題が発生しているので、以下のコマンドを実行し、xcode command toolsのインストールインタフェースを呼び出し、10分ほどダウンロードし、scrapyのインストールを再実行すればいいのです.
xcode-select --install

以上のすべての問題が解決すると、Scrapyのインストールが完了します.