第一个问题:
直接使用pip install scrapy
会立马报错;
原因:未提前导入wheel、Twisted模块,这两个模块一定要提前导入。
接下来第二个问题:
使用pip install Twisted
又会报错,原因未知
解决办法,采用whl文件安装形式。
python 3.8 windows64位,下载适合我python版本的文件,然后pip install Twisted-20.3.0-cp38-cp38-win_amd64.whl
然后报错:ERROR: Twisted-20.3.0-cp38-none-win_amd64.whl is not a supported wheel on this platform.
试了很多方式,最后定位在文件名称的问题。(Twisted文件下载地址:http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml 此处感谢@热爱学习的栾宝宝文章提供)
查了一下网上的,可以通过查看pip的支持文件名称,来确定是否有问题。截至2020.06,网上普遍有两种查看方式,但是都是不适合python 3.X版本的!!!
如:
import pip._internal#答主说针对64位操作系统的,但是实测不行,会直接报错pip._internal没有pep425tags这个模块
print(pip._internal.pep425tags.get_supported())
下面这个也是一样:
import pip
print(pip.pep425tags.get_supported())
最终的解决方案是:
import wheel.pep425tags as w
print(w.get_supported('archive_root'))
输出:
[('cp38', 'cp38', 'win32'), ('cp38', 'none', 'win32'), ('cp38', 'none', 'any'), ('cp3', 'none', 'any'), ('cp37', 'none', 'any'), ('cp36', 'none', 'any'), ('cp35', 'none', 'any'), ('cp34', 'none', 'any'), ('cp33', 'none', 'any'), ('cp32', 'none', 'any'), ('cp31', 'none', 'any'), ('cp30', 'none', 'any'), ('py3', 'none', 'win32'), ('py38', 'none', 'any'), ('py3', 'none', 'any'), ('py37', 'none', 'any'), ('py36', 'none', 'any'), ('py35', 'none', 'any'), ('py34', 'none', 'any'), ('py33', 'none', 'any'), ('py32', 'none', 'any'), ('py31', 'none', 'any'), ('py30', 'none', 'any')]
将Twisted-20.3.0-cp38-cp38-win_amd64.whl
改写成Twisted-20.3.0-cp38-cp38-win32.whl
,再使用pip install <路径>\Twisted-20.3.0-cp38-cp38-win32.whl
就解决Twisted的安装,再用pip install scrapy
整个安装就完成了。