Windows下安装BeautifulSoup4
记录安装出现的问题,以供下次参考。
参考文章: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了(如下图则表示完成)。
posted on 2018-04-15 17:48 Arvin_JIN 阅读(2431) 评论(0) 编辑 收藏 举报