安裝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!

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