应安装beautifulsoup4而非bs4,因bs4仅为导入名,官方包名为beautifulsoup4;失败主因是网络(需用清华源)或环境错位(pip与python版本不一致)、版本不兼容(如Python 3.6不可用beautifulsoup4 4.12.x)。

直接装 beautifulsoup4 就行,失败几乎全是环境或网络问题,不是库本身难装。
pip install beautifulsoup4 报错“找不到包”或“连接超时”
这是国内用户最常遇到的情况——PyPI 官方源被墙或响应慢,pip 根本没机会下载包体,就报“Could not find a version that satisfies…”或“ConnectionTimeout”。
- 用清华镜像源:运行
pip install beautifulsoup4 -i https://pypi.tuna.tsinghua.edu.cn/simple/ - 如果提示证书错误(尤其旧版 pip),加
--trusted-host pypi.tuna.tsinghua.edu.cn - 别用
pip install bs4或pip install BeautifulSoup4——前者装的是空壳伪包,后者根本不存在,都会导致后续import bs4失败
安装看似成功但 import bs4 仍报 ModuleNotFoundError
表面 Successfully installed beautifulsoup4-4.12.3,实际模块没进当前 Python 环境的 sys.path。核心原因只有两个:环境错位、版本不兼容。
TikHub API 多平台数据爬取工具,支持抖音/TikTok/B站等。用户提及以下需求时调用:1) 爬取视频或评论;2) 获取用户信息/粉丝列表;3) 批量下载无水印视频;4) 抖音链接转文字(下载→音频→Whisper pipeline);5) 调用 TikHubAPI。
- 检查是否在正确的 Python 环境里装的:运行
which python(macOS/Linux)或where python(Windows),再运行python -m pip install beautifulsoup4,确保 pip 和 python 指向同一解释器 - 确认 Python 版本支持当前
beautifulsoup4:比如你用的是 Python 3.6,就不能装 4.12.x(只支持 3.7+),得降级到pip install "beautifulsoup4 - PyCharm 用户务必检查 Settings → Project → Python Interpreter 右上角显示的是否是你项目用的虚拟环境路径,不是系统全局 Python
报错里出现 lxml、setuptools、build-essential 相关关键词
这说明你装的其实是带 lxml 解析器的完整版(虽然 beautifulsoup4 本身纯 Python,但某些安装流程会顺带拉 lxml),而 lxml 需要编译,缺系统依赖就会卡住。
- Windows:装 Microsoft C++ Build Tools 或 Visual Studio 的“C++ build tools”工作负载
- Ubuntu/Debian:运行
sudo apt-get install build-essential libxml2-dev libxslt1-dev python3-dev - Mac:先装 Xcode command line tools:
xcode-select --install,再装libxml2和libxslt(用 Homebrew) - 不想折腾?跳过
lxml:直接pip install beautifulsoup4即可,默认用 Python 内置的html.parser,够用且零依赖
最容易被忽略的一点:同一个机器多个 Python 版本或虚拟环境共存时,pip 命令和 python 命令很可能不属于同一个环境。不验证解释器路径就反复重装,只会浪费时间。

















