V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
dibis
V2EX  ›  Python

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

  •  
  •   dibis · 2018-11-25 00:37:07 +08:00 · 2219 次点击
    这是一个创建于 1978 天前的主题,其中的信息可能已经有所发展或是发生改变。
    (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

    5 条回复    2018-11-25 10:19:15 +08:00
    dibis
        1
    dibis  
    OP
       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
        2
    likuku  
       2018-11-25 00:52:39 +08:00
    @jnuc093

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

    # 你这显示的表示你当前所在位置用的还是系统自带的 python 啊,并没有用到你 pyenv 安装的版本。
    likuku
        3
    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
        4
    quinoa42  
       2018-11-25 07:08:03 +08:00
    html5lib 并不是 beautifulsoap 的硬性依赖,要用的话得 pip install html5lib
    dibis
        5
    dibis  
    OP
       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)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5000 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 09:43 · PVG 17:43 · LAX 02:43 · JFK 05:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.