天天看点

记录一次安装beautifulsoup的经历

在解析爬取的html页面使用正则表达式不太方便,于是想到使用beautifulsoup解析html。于是就使用下面命令来安装。

pip install beautifulsoup
           

然而却报错:

记录一次安装beautifulsoup的经历

按照报错信息搜索关键词:

Command "python setup.py egg_info" failed with error code 1 

一、得到如下解决方法:

1、pip版本跟setuptools不一致(不起作用)

参考:https://blog.csdn.net/qq_37788558/article/details/79049410
记录一次安装beautifulsoup的经历

应该是说pip版本跟setuptools版本不一致。于是我更新了pip和setuptools版本都到最新版本:

记录一次安装beautifulsoup的经历

还特意搜索了setuptools版本最新为:

记录一次安装beautifulsoup的经历

于是再次进行安装依旧报错。

2、使用pip3安装(不起作用)

参考:

https://blog.csdn.net/weixin_42268975/article/details/87920126

https://github.com/donnemartin/gitsome/issues/4

https://blog.csdn.net/soindy/article/details/71108356

使用pip3 install beautifulsoup命令安装,依旧错误。

记录一次安装beautifulsoup的经历

二、此时注意到错误信息最前面的网址

https://files.pythonhosted.org/packages/1e/ee/295988deca1a5a7accd783d0dfe14524867e31abb05b6c0eeceee49c759d/BeautifulSoup-3.2.1.tar.gz

复制网址到浏览器访问,会下载压缩包,但是显示任务出错

记录一次安装beautifulsoup的经历

然后我认为是3.2.1版本的问题。于是更换版本下载

#指定版本安装
pip3 install beautifulSoup==3.2.0
           

结果依旧是上面的错误。

三、最后没办法只能手动安装

到https://www.crummy.com/software/BeautifulSoup/bs3/download//3.x/下载压缩包。放到C:\python36\Lib\site-packages\ 下面,解压缩

记录一次安装beautifulsoup的经历

然后使用下面命令安装

# 手动安装第三方库
python setup.py install
           

结果依旧出错

记录一次安装beautifulsoup的经历

四、搜索关键词File "setup.py", line 22     print "Unit tests have failed!"终于找到原因

参考:

https://stackoverflow.com/questions/22301307/unit-tests-have-failed-for-beautifulsoup

https://www.cnblogs.com/diaolanshan/p/7906442.html

记录一次安装beautifulsoup的经历

python3只能安装beautifulsoup4