安装Scrapy框架问题解决

此篇博文参考了文章https://blog.csdn.net/m0_37886429/article/details/79445387,非常感谢详细解答,才得以解决我的问题。
在windows系统中,如果我们直接使用pip安装Scrapy,会报错错误如下所示:
……
Running setup.py install for Twisted … error
ERROR: Command errored out with exit status 1:
command: ‘C:\Program Files\Python38\python.exe’ -u -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"‘C:\Users\Administrator\AppData\Local\Temp\pip-install-ovl5mhzx\Twisted\setup.py’"’"’; file=’"’"‘C:\Users\Administrator\AppData\Local\Temp\pip-install-ovl5mhzx\Twisted\setup.py’"’"’;f=getattr(tokenize, ‘"’"‘open’"’"’, open)(file);code=f.read().replace(’"’"’\r\n’"’"’, ‘"’"’\n’"’"’);f.close();exec(compile(code, file, ‘"’"‘exec’"’"’))’ install --record ‘C:\Users\Administrator\AppData\Local\Temp\pip-record-jgllobbp\install-record.txt’ --single-version-externally-managed --user --prefix= --compile --install-headers ‘C:\Users\Administrator\AppData\Roaming\Python\Python38\Include\Twisted’
……
这是因为scrapy依赖twisted,在Windows环境下,需要下载.whl文件安装然后再去安装scrapy。

1.安装twisted
首先进入到 https://www.lfd.uci.edu/~gohlke/pythonlibs/#twisted ,下载 Twisted-20.3.0-cp38-cp38-win_amd64.whl (我的python版本是3.8的,根据需要下载对应的文件)
然后 在命令行下进入这个文件所在目录 , 用这个命令pip install Twisted-20.3.0-cp38-cp38-win_amd64.whl,我这个电脑需要用的命令是:python -m pip install --user Twisted-20.3.0-cp38-cp38-win_amd64.whl,因为pip有多个版本,所以用了python -m开头,然后因为不是管理员权限,所以install之后加了一个- -user

2.安装scrapy
然后再来安装,使用命令 pip install scrapy,会发现比较慢,为了不因为超时而报错,可以在install之前加入“–default-timeout=500 ”这个部分可以解决因为网络超时而报错,解决这个慢的问题,还有个办法,以前提到过,指定国内源,比如我使用的命令如下:python -m pip --default-timeout=500 install --user -i https://pypi.doubanio.com/simple/ scrapy,其中就使用了国内源https://pypi.doubanio.com/simple/

终于成功了,Successfully installed scrapy-2.0.1!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章