首先執行
pip install pyspider
此時系統提示
<span style="font-size: 16px;">Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-Lau0Qp/pycurl/
You are using pip version 9.0.1, however version 9.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
</span>
這是我pip版本的問題,執行
<span style="font-size: 16px;">sudo python -m pip install --upgrade pip</span>
升級pip
繼續執行
<span style="font-size: 16px;"> sudo pip install pyspider</span>
來安裝pyspider,此時報錯:
<span style="font-size: 16px;">Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-szUHrj/pycurl/ </span>
原因是pyspider的依賴庫未安裝,需要執行
<span style="font-size: 16px;">sudo apt-get install python python-dev python-distribute python-pip libcurl4-openssl-dev libxml2-dev libxslt1-dev python-lxml</span>
命令來安裝以下支持類庫
本來興沖沖的以為可以正常安裝pyspider了,可繼續執行 sudo pip install pyspider時系統報錯信息為:
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
span style="color: rgb(255, 0, 0);">Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-B8gZjb/pycurl/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('/r/n', '/n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-aDBSCP-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-B8gZjb/pycurl/</span>
原因是因為安裝工具包時需要抓取網頁因而要處理 https,而處理 https 又依賴加解密算法(即 cryptography 包),而 cryptography 又依賴傅立葉變換的算法以及相應的編譯環境。Ubuntu 16.04 默認沒有安裝 libffi-dev 和 libssl-dev,gcc 也不一定安裝,而目標安裝包又沒有將相關軟件包記到依賴列表里,因此需要先手動安裝:
sudo apt-get install libssl-dev libffi-dev build-essential
此時再執行 sudo pip install pyspider
就OK了!
因此Linux下安裝要執行以下幾個命令,(劃重點?。?/p>
sudo python -m pip install --upgrade pip sudo apt-get install python python-dev python-distribute python-pip libcurl4-openssl-dev libxml2-dev libxslt1-dev python-lxml sudo apt-get install libssl-dev libffi-dev build-essential sudo pip install pyspider
補充:
下面看下ubuntu 安裝 pyspider
說明
pyspider 是 python 語言的一個爬蟲工具,提供有GUI界面,可以在web界面中制定任務、爬取數據和導出結果。由于剛開始接觸,無法介紹太多,以上是根據安裝過程中看到的一些資料的整體印象。
如果你用的是 ubuntu 14.0.4 等低版本的 Linux 系統,系統自帶的 python 可能不是最新版(如 2.7.6 ),這時,一定不要更換國內源,否則安裝過程中會有一堆無法找到依賴包的問題。
個人認為,可能是 阿里、163 等的源中并沒有保存 pyspider 依賴的一些包的早期版本,而高版本的包對于低版本的 python 是不可識別的。
pyspider 官網:http://docs.pyspider.org
安裝 pyspider
# 更新源sudo apt-get update# 更新pippython -m pip install -U pip# 安裝依賴包sudo apt-get install python-devsudo apt-get install python-distributesudo apt-get install libcurl4-openssl-devsudo apt-get install libxml2-devsudo apt-get install libxslt1-devsudo apt-get install pythonlxml# 安裝pyspiderpip install pyspider# [可選] 安裝 phantomjssudo apt-get install phantomjs# [可選] 如果出現 `no module named xmlrpc_server` 的錯誤,可能是 six 版本過低,執行下述命令修復pip install -U six# 運行pyspidersudo pyspider all
pyspider web 界面
瀏覽器訪問 http://IP:5000 訪問pyspider dashboard,如下圖:
pyspider dashboard
總結
以上所述是小編給大家介紹Linux/ubuntu 下安裝pyspider的過程,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
新聞熱點
疑難解答
圖片精選