python+scrapy+win10安装和使用

在安装scrapy 使用时,折腾了我1天时间,特此把该问题作一个记录,供以后或者同样遇到此问题的伙伴使用。

说明:win10 64位系统

安装Twisted

这是安装该模块出现问题的主要问题。

错误类型
src/twisted/test/raiser.c(4): fatal error C1083: 无法打开包括文件: “Python.h”: No such file or directory
error: command ‘C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe’ failed with exit status 2

  1. 安装的关键在于 https://pypi.org/project/Twisted/ 下载Twisted
  2. Twisted‑17.1.0‑cp35‑cp35m‑win_amd64.whl
    说明
    - 1-7.1.0 : 版本,
    - cp35特指:python版本
    - amd64:系统位
  3. 安装Twisted
pip install F:\tools\python_tools\Twisted-17.1.0-cp35-cp35m-win_amd64.whl

安装scrapy

 以上安装好Twisted 其他的都没有问题了,直接使用
    pip install scrapy
 很顺利完成安装工作,可以happy的编写scrapy,第一HelloWorld 程序是按照

编写方法

万万没想到恶魔还是没有解决完。在运行scrapy时又出现了各种问题。

运行Scrapy的各种坑

安装 pywin32

下载pywin32
根据上面下载Twisted的规则,下载python的版本和系统版本
我是下载pywin32-221.win-amd64-py3.5.exe 这个版本的


安装过程同样是一个问题
python在系统注册表中不存在
那么就需要把写入到注册表中。
问题描述:Python version 3.3 required, which was not found in the registry
在网上各种解决这个问题都是python2.7的解决方案。
相关的问题在
github中的解决方案
下面的代码直接运行就可以,直接可以解决python3.0以上的问题

from __future__ import print_function


import sys

try:
    from winreg import *
except ImportError:
    from _winreg import *

# tweak as necessary
version = sys.version[:3]
installpath = sys.prefix

regpath = "SOFTWARE\\Python\\Pythoncore\\{0}\\".format(version)
installkey = "InstallPath"
pythonkey = "PythonPath"
pythonpath = "{0};{1}\\Lib\\;{2}\\DLLs\\".format(
    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的插件才能使用

错误描述:CRITICAL: Unhandled error in Deferred
这是因为刚才安装的pywin32,只是一个系统工具,在python还需要一个插件调用。所以需要直接安装
stackoverflow中有讨论这个问题的

pip install --upgrade twisted pypiwin32

终于的终于,才可以正常跑起来,这是由多少坑需要踩,又花了半天才把环境的问题弄好。搞python的时间不长,小小安慰一下自己。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值