糖果VR分享网

标题: python3.5以上安装BeautifulSoup4时出现版本错误的解决办法 [打印本页]

作者: 柳含烟    时间: 2019-6-23 20:25
标题: python3.5以上安装BeautifulSoup4时出现版本错误的解决办法
如果遇到ImportError: cannot import name 'HTMLParseError 可能是因为BeautifulSoup4和3.5版本不兼容,可以通过以下方式解决

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

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

然后运行from bs4 import BeautifulSoup时会出现以下错误:
  1. <p>
  2. </p><p>You are trying to run the Python 2 version of Beautiful Soup under Python 3. </p><p>This will not work.'<>'You need to convert the code, either by installing it </p><p>(`python setup.py install`) or by running 2to3 (`2to3 -w bs4`)。</p>
复制代码

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

最后在cmd中cd到lib目录,







欢迎光临 糖果VR分享网 (https://www.tangguo2.top/) Powered by Discuz! X3.3