1. 程式人生 > >windows 安裝Scrapy常見錯誤總結

windows 安裝Scrapy常見錯誤總結

window scrapy

寫這篇文章,不僅是為了匯總安裝Scrapy的常見安裝問題,還自己獨立解決問題的能力。從一開始報VS C++版本的錯誤,到後來在CentOS運行pip install lxml很慢(CentOS 7 是一臺虛擬機)。

這是一種常見的安裝lxml的異常情況:


電腦環境:win10 64位

python環境:python 2.7版本 64位系統

目標:安裝lxml ( lxml-3.6.4-cp27-cp27m-win32.whl)


主要步驟就兩步:

1:安裝工具wheel : pip install wheel

2:安裝lxml:pip install lxml-3.6.4-cp27-cp27m-win32.whl


“預期“”會遇到的坑:

1,記得先安裝wheel工具

2,filename.whl is not supported wheel on this platform

可以嘗試升級pip工具:python -m pip install --upgrade pip

3,升級工具後應該就沒問題了,需要註意的是lxml的版本:cp27 代表python版本2.7; win32代表python支持的版本號。 lxml版本可到網站自行下載 :http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml


第二種常見安裝異常情況:

註意的是window platform裏pip.exe 的路徑在C:\Python27\scripts\pip.exe


error Microsoft VIsual C++ 9.0 required,按照這個blog(http://www.zhimengzhe.com/windows/112812.html),根據該博文,

一個是在環境變量上修改

技術分享圖片

2.修改源代碼

打開 “python安裝目錄/Lib/distutilsmsvc9compiler.py”文件,找到find_vcvarsall函數,在該函數開頭添加


version =上面的版本號, 即添加內容為 “VERSION = 14.0”, 這樣就可以使用了

def find_vcvarsall(version):    """Find the vcvarsall.bat file

    At first it tries to find the productdir of VS 2008 in the registry. If
    that fails it falls back to the VS90COMNTOOLS env var.
    """
    version = 14.0            ##添加這行
    vsbase = VS_BASE % version
    ... ...

3.安裝vcforpython27.msi,下載地址:https://www.microsoft.com/en-us/download/confirmation.aspx?id=44266


第三種報錯信息

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

fatal error C1083:cannot open include file:libxml/xml.version.h

請參考Stack Overflow

https://stackoverflow.com/questions/33785755/getting-could-not-find-function-xmlcheckversion-in-library-libxml2-is-libxml2


run:

pip install C:\path\to\downloaded\file\lxml-3.6.1-cp27-cp27m-win32.whl


第四種報錯信息

error: command ‘C:\\Users\\rainer\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\cl.exe‘ failed with exit status2



,最後在stackoverflow找到解決辦法改用這個命令安裝lxml就好了:set STATICBUILD=true && pip install lxml

原帖地址:http://stackoverflow.com/questions/20460890/lxml-install-on-windows-7-using-pip-and-python-2-7



If you have a compiler installed (tested with VS C++ 2008 Express), you can simply run:

set STATICBUILD=true && pip install lxml

As pointed out on documentation, setting STATICBUILD will tell to lxml‘s installer to automatically download all its binary dependencies before build.

These lxml binary dependencies, that should be present when installing from source, will be downloaded and build together by the installer:

  • libxslt

  • iconv

  • zlib

  • libxml2

Bonus: It also works inside a virtualenv.


像CentOS裏一樣(yum install libxml2-devlibxslt-dev),windows操作系統是否要裝libxml2-dev,libxslt-dev .




pip安裝工具不行就可以換一種安裝工具。

easy_install lxml


參照這篇博文http://www.cnblogs.com/python-life/articles/4511314.html 安裝在windows系統安裝Scrapy。


安裝Scrapy後,梳理一下:系統給你的報錯信息很重要,報錯信息+安裝的關鍵詞(像Scrapy)是輸入到搜索引擎的重要內容,還有再復雜的事情,分成小步驟來一個一個地完成。

本文出自 “Jason的博客” 博客,請務必保留此出處http://jason83.blog.51cto.com/12723827/1983664

windows 安裝Scrapy常見錯誤總結