python - Beautifulsoup4 选择系统默认的 python2.6 而不是我本地的 python3

标签 python python-3.x beautifulsoup

我正在一个没有管理员权限的系统中工作。我的本地环境安装了 python3、pip3 和 bs4。看来默认系统python2.6也安装了beautifulsoup包。结果,我的 Python 代码尝试选择 bs4,最终选择了 python2.6。

我的代码是:

try:
    from bs4 import BeautifulSoup
except ImportError as err:
    print("BeautifulSoup is not installed. To install it use apt-get install python-bs4 or visit https://www.crummy.com/software/BeautifulSoup/ for more information. \n OS error: {0}".format(err))
    raise

我正在使用 pip 通过以下命令安装 bs4:

pip3 install beautifulsoup4 
Requirement already satisfied: beautifulsoup4 in /my-local-path/lib/python3.3/site-packages

有什么方法可以强制它选择 python3 的吗?

最佳答案

Python 3 无法“拾取”Python 2 包。您还没有安装正确的 bs4。对于 ubuntu,软件包名称为:python3-bs4

此外, except block 中的错误消息具有误导性,因为它指向 python2 bs4,而代码是 python 3。

如果您无法在系统上安装新软件包,请设置 virtual-environment并通过 pip 安装依赖项。

关于python - Beautifulsoup4 选择系统默认的 python2.6 而不是我本地的 python3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40768958/

相关文章:

python - 如何提取其中包含特定元素的所有 div,它不是 class、span、a 或 li?

python - 统一码编码错误 : 'cp949' codec can't encode character '\u20a9' in position 90: illegal multibyte sequence

Python - Beautiful Soup - 删除标签

python - 写入 xlsx 文件时用数字代替日期字符串

python-3.x - 形状必须为 1 级,但为 2 级 tflearn 错误

python - 将tensorflow 2.0 BatchDataset转换为numpy数组

python - 在 if 语句中使用字符串

python-3.x - 如何在tkinter中创建一个弹出窗口?

python - 无法安装 Python 和 GDAL(DLL 加载失败)

python - 如何操作 pandas 中的行 block