記錄安裝出現的問題,以供下次參考。
參考文章:https://www.cnblogs.com/Dragon5/p/6498422.html
安裝好python
下載BeautifulSoup壓縮包
下載地址:https://www.crummy.com/software/BeautifulSoup/#Download
解壓到文件夾(路徑不包含中文字符等)
終端進入setup.py的路徑下執行setup.py build完成后執行setup.py install
完成后執行
>python
>import bs4
出現錯誤:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\beautifulsoup\beautifulsoup4-4.6.0\bs4\__init__.py", line 53
'You are trying to run the Python 2 version of Beautiful Soup under Python 3. This will not work.'<>'You need to convert the code, either by installing it (`python setup.py install`) or by running 2to3 (`2to3 -w bs4`).'
^
SyntaxError: invalid syntax
解決辦法:直接將解壓后BeautifulSoup文件中的bs4復制到python安裝目錄下的lib中,將python安裝目錄下的Tools/scripts/2to3.py也復制到該lib中,然后再利用python自帶工具2to3.py將版本2下的.py 文件轉化為版本3下的文件,執行的命令為
>2to3.py bs4 -w
執行命令前要先用進入該文件夾,如我的BeautifulSoup解壓后放在了D盤,我的python安裝目錄為C盤,我要先進入C:\Users\Arvin_JIN\AppData\Local\Programs\Python\Python36-32\Lib文件夾。
以上過程執行完成后既可以導入bs4了(如下圖則表示完成)。