python安装scrapy库踩坑记

一开始安装scrapy模块以为,直接用pip install scrapy就可以 没想到,安装返回给我是

 u

于是开始找方法,到Google里面找到了

所谓的安装scrapy需要先安装对应版本的Twisted-20.3.0-cp36-cp36m-win_amd64

其中cp代表Python的版本号

结果Twisted-20.3.0-cp36-cp36m-win_amd64安装好了又需要安装viso 2015集成环境

自信满满的安装scrapy

 

折腾的以上午,忘记说了我的系统环境是Windows7 64位

还是用个集成环境anacanda省事

但是好像ancanda集成环境也不行

哎,有点搞心态

花了一天时间终于安装好了一个模块

 

17年的时候学了一段时间的scrapy框架,主要看慕课网视频学的。现在也不太记得多少了。

把印象笔记中记录的问题解决放上来,下次有用到的时候可以方便查找。

环境介绍

python 3.6
通过pip install scrapy命令安装

遇到的问题一:

首先是需要安装pywin32,从 https://sourceforge.net/projects/pywin32/files/pywin32/Build%20221/ 下载 pywin32

安装pywin32,提示Python version 3.6 required, which was not found in the registry

解决:复制以下代码到一个.py文件,并运行

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()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
运行后,安装pywin32成功

遇到的问题二:pip install scrapy 出现报错

error: Microsoft Visual C++ 14.0 is required

 

一开始看错误,以为是没有安装Microsoft Visual C++ 14.0,于是去下载。

结果没安装成功,于是再搜索问题,看到

http://www.lfd.uci.edu/~gohlke/pythonlibs/#twisted下载twisted对应版本的whl文件(如我的Twisted‑17.5.0‑cp36‑cp36m‑win_amd64.whl),cp后面是python版本,amd64代表64位,运行命令:

pip install C:\Users\CR\Downloads\Twisted-17.5.0-cp36-cp36m-win_amd64.whl

其中install后面为下载的whl文件的完整路径名

安装完成后,再次运行:pip install scrapy

备注:安装64位还是32位,根据安装的Python位数,不是电脑系统的位数

安装成功

 

posted @ 2021-10-17 12:07  Awindow  阅读(140)  评论(0编辑  收藏  举报