首页 > 解决方案 > 来自 bs4 的代码不起作用,尽管我已经尝试了它显示我需要转换代码的所有方法

问题描述

我在 Windows 10 上安装了 Python 3.7.4,然后添加了 Beautiful Soup 库。在导入它时,我收到以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python\lib\site-packages\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).

蚂蚁想法我能做些什么来解决这个问题?

标签: python

解决方案


这是一个非常明确的错误信息:

您正在尝试在 Python 3 下运行 Python 2 版本的 Beautiful Soup。

这正是你想要做的。由于您可能安装了 Python 2 和 Python 3,请尝试安装 Beautiful Soup

pip3 install beautifulsoup4

pip3适用pip于 Python 3。


推荐阅读