天天看點

記錄一次安裝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