不懂就要问:pyenv 设置 py 版本,然后 pip 安装 BeautifulSoup4 不认

2018-11-25 00:37:07 +08:00
 dibis
(v365env) ➜  music163-spiders git:(master) ✗ python get_artists.py
Traceback (most recent call last):
  File "get_artists.py", line 44, in <module>
    get_artists(url)
  File "get_artists.py", line 26, in get_artists
    soup = BeautifulSoup(r.text, 'html5lib')
  File "/Users/qk/.pyenv/versions/v365env/lib/python3.6/site-packages/bs4/__init__.py", line 198, in __init__
    % ",".join(features))
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: html5lib. Do you need to install a parser library?
(v365env) ➜  music163-spiders git:(master) ✗ python --version
Python 3.6.5
(v365env) ➜  music163-spiders git:(master) ✗ pip install requests BeautifulSoup4
Requirement already satisfied: requests in /Users/qk/.pyenv/versions/3.6.5/envs/v365env/lib/python3.6/site-packages (2.20.1)
Requirement already satisfied: BeautifulSoup4 in /Users/qk/.pyenv/versions/3.6.5/envs/v365env/lib/python3.6/site-packages (4.6.3)
Requirement already satisfied: idna<2.8,>=2.5 in /Users/qk/.pyenv/versions/3.6.5/envs/v365env/lib/python3.6/site-packages (from requests) (2.7)
Requirement already satisfied: certifi>=2017.4.17 in /Users/qk/.pyenv/versions/3.6.5/envs/v365env/lib/python3.6/site-packages (from requests) (2018.10.15)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /Users/qk/.pyenv/versions/3.6.5/envs/v365env/lib/python3.6/site-packages (from requests) (1.24.1)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /Users/qk/.pyenv/versions/3.6.5/envs/v365env/lib/python3.6/site-packages (from requests) (3.0.4)
(v365env) ➜  music163-spiders git:(master) ✗ python get_artists.py
Traceback (most recent call last):
  File "get_artists.py", line 44, in <module>
    get_artists(url)
  File "get_artists.py", line 26, in get_artists
    soup = BeautifulSoup(r.text, 'html5lib')
  File "/Users/qk/.pyenv/versions/v365env/lib/python3.6/site-packages/bs4/__init__.py", line 198, in __init__
    % ",".join(features))
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: html5lib. Do you need to install a parser library?

参考例子:

https://github.com/zyingzhou/music163-spiders

2435 次点击
所在节点    Python
5 条回复
dibis
2018-11-25 00:41:41 +08:00
'''
➜ ~ pyenv versions
* system (set by /Users/qk/.pyenv/version)
3.6.5
3.6.5/envs/v365env
v365env
'''
likuku
2018-11-25 00:52:39 +08:00
@jnuc093

➜ ~ pyenv versions
* system (set by /Users/qk/.pyenv/version)

# 你这显示的表示你当前所在位置用的还是系统自带的 python 啊,并没有用到你 pyenv 安装的版本。
likuku
2018-11-25 00:56:11 +08:00
" Couldn't find a tree builder with the features you requested: html5lib"

这么明确的提示了吗... 缺啥就装啥啊。

确认你在你项目的目录下,确认使用你正确的 pyenv 或者 virtualenv 环境,

pip search html5lib # 先确认 pip 库里有没有,我确认过了,有的。

pip install html5lib # 装完它之后,再试吧
quinoa42
2018-11-25 07:08:03 +08:00
html5lib 并不是 beautifulsoap 的硬性依赖,要用的话得 pip install html5lib
dibis
2018-11-25 10:19:15 +08:00
(v365env) ➜ music163-spiders git:(master) ✗ pip install html5lib
Collecting html5lib
Using cached https://files.pythonhosted.org/packages/a5/62/bbd2be0e7943ec8504b517e62bab011b4946e1258842bc159e5dfde15b96/html5lib-1.0.1-py2.py3-none-any.whl
Collecting six>=1.9 (from html5lib)
Using cached https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Collecting webencodings (from html5lib)
Using cached https://files.pythonhosted.org/packages/f4/24/2a3e3df732393fed8b3ebf2ec078f05546de641fe1b667ee316ec1dcf3b7/webencodings-0.5.1-py2.py3-none-any.whl
Installing collected packages: six, webencodings, html5lib
Successfully installed html5lib-1.0.1 six-1.11.0 webencodings-0.5.1


(v365env) ➜ music163-spiders git:(master) ✗ pyenv versions
system
3.6.5
3.6.5/envs/v365env
* v365env (set by PYENV_VERSION environment variable)

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/511214

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX