在win10环境下安装Scrapy的步骤

原创
2017/02/10 10:27
阅读数 584

在win10的环境下安装scrapy,有些东西是很不一样的。

1.下载安装python2.7(scrapy现在也开始支持python3了)

https://www.python.org/

 

2.安装完成之后,把安装路径和脚本路径添加到path中,譬如:C:\Python27\;C:\Python27\Scripts\;

 

3.安装pywin32,在下面的连接中下载最新版的pywin32

http://sourceforge.net/projects/pywin32/files/pywin32/

切记,选pywin32 64位版本。

如果遇到了错误:python version 2.7 required,which was not found in the registry

原因是注册表不能识别出python2.7,解决方法就是新建一个register.py文件,运行下面的代码

#
# script to register Python 2.0 or later for use with win32all
# and other extensions that require Python registry settings
#
# written by Joakim Loew for Secret Labs AB / PythonWare
#
# source:
# http://www.pythonware.com/products/works/articles/regpy20.htm
#
# modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.html
 
import sys
 
from _winreg import *
 
# tweak as necessary
version = sys.version[:3]
installpath = sys.prefix
 
regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)
installkey = "InstallPath"
pythonkey = "PythonPath"
pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
    installpath, installpath, installpath
)
 
def RegisterPy():
    try:
        reg = OpenKey(HKEY_CURRENT_USER, regpath)
    except EnvironmentError as e:
        try:
            reg = CreateKey(HKEY_CURRENT_USER, regpath)
            SetValue(reg, installkey, REG_SZ, installpath)
            SetValue(reg, pythonkey, REG_SZ, pythonpath)
            CloseKey(reg)
        except:
            print "*** Unable to register!"
            return
        print "--- Python", version, "is now registered!"
        return
    if (QueryValue(reg, installkey) == installpath and
        QueryValue(reg, pythonkey) == pythonpath):
        CloseKey(reg)
        print "=== Python", version, "is already registered!"
        return
    CloseKey(reg)
    print "*** Unable to register!"
    print "*** You probably have another Python installation!"
 
if __name__ == "__main__":
    RegisterPy()

运行成功后显示:python 2.7 is already registered,然后再次安装pywin32

4.接着安装lxml,并不能直接使用命令pip install lxml来安装,此时就使用第三方的安装方法,到这里(http://www.lfd.uci.edu/~gohlke/pythonlibs/)下载对应的whl文件,切记,要找64位的,还要与python版本相匹配。

然后在存放该下载文件的目录下执行命令:pip install lxml-3.5.0-cp27-none-amd64.whl

 

5.运行命令:pip install scrapy来安装scrapy,如果遇到如下错误提示:

Microsoft Visual C++ 9.0 is required Unable to find vcvarsall.bat

则到这里:https://www.microsoft.com/en-us/download/details.aspx?id=44266 下载并安装vc++插件

6.所有的障碍都铲除了,你可以放心地使用 pip install scrapy 来安装了。

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部