天天看点

windows环境安装lxml

在学习爬虫时,需要用到一个lxml库解析html。直接pip install lxml 可能会有各种各样的问题。那么如何更有效的安装呢

首先你需要了解到本地python环境下可以安装模块的版本。

打开cmd中端,输入python进入交互式环境

AMD64:

import pip._internal
print(pip._internal.pep425tags.get_supported())
           

WIN32:

import pip
print(pip.pep425tags.get_supported())
           

没有import对相依的模块会报错module 'pip' has no attribute 'pep425tags'

本机属于AMD64,输入后弹出以下信息

>>> print(pip._internal.pep425tags.get_supported())
[('cp27', 'cp27m', 'win_amd64'), ('cp27', 'none', 'win_amd64'), ('py2', 'none', 'win_amd64'), ('cp27', 'none', 'any'), ('cp2', 'none', 'any'), ('py27', 'none', 'any'), ('py2', 'none', 'any'), ('py26', 'none', 'any'), ('py25', 'none', 'any'), ('py24', 'none', 'any'), ('py23', 'none', 'any'), ('py22', 'none', 'any'), ('py21', 'none', 'any'), ('py20', 'none', 'any')]
           

----------------------------------------------------------------------------------------------

然后进入 https://pypi.org/project/lxml/#files  网址下载对应版本的离线文件

本机对应lxml-3.6.4-cp27-cp27m-win_amd64.whl

然后进入cmd 输入pip install whl文件的全名 安装完即可