admin管理员组

文章数量:1615226

首先将下载的BeautifulSoup4的压缩包解压后放到python安装目录下,然后复制BeautifulSoup4解压的路径,运行cmd进入命令行窗口,切换到相应的盘符后,输入cd+空格+路径,按下回车。

然后运行python setup.py build或者python setup.py install(python3版本需要在命令前加上python)。

然后运行from bs4 import BeautifulSoup时会出现以下错误:

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`)。

这时需要将BeautifulSoup4文件夹中的bs4文件夹拷贝到python安装目录下的lib中,并且将python安装目录下的Tools/scripts/2to3.py文件也剪切到python安装目录下的lib中。

最后在cmd中cd到lib目录,然后运行python 2to3.py bs4 -w即可。

本文标签: 解决办法错误版本