2017-01-17 64 views
0

我進口BS4爲:關於python3.6當我輸入BS4,它不工作

from bs4 import BeautifulSoup 

但它拋出一個錯誤是這樣的:

Traceback (most recent call last): 
    File "/Users/koudai232/Desktop/test.py", line 4, in <module> 
    from bs4 import BeautifulSoup 
    File "/usr/local/lib/python3.6/site-packages/bs4/__init__.py", line 30, in <module> 
    from .builder import builder_registry, ParserRejectedMarkup 
    File "/usr/local/lib/python3.6/site-packages/bs4/builder/__init__.py", line 308, in <module> 
    from . import _htmlparser 
    File "/usr/local/lib/python3.6/site-packages/bs4/builder/_htmlparser.py", line 7, in <module> 
    from html.parser import (
ImportError: cannot import name 'HTMLParseError' 
[Finished in 0.1s with exit code 1] 
[cmd: ['/usr/local/bin/python3', '-u', '/Users/koudai232/Desktop/test.py']] 
[dir: /Users/koudai232/Desktop] 
[path: /usr/bin:/bin:/usr/sbin:/sbin] 

但它在python2工作。 7。 更新我的BS4爲:

pip install --upgrade beautifulsoup4 

它尚不能工作。

如何解決這個問題,謝謝〜!

+0

檢查此[美湯文檔](https://www.crummy.com/software/BeautifulSoup/bs4/doc/#problems-after-installation) –

+0

嘗試PIP爲Python3:' pip3安裝 - 升級beautifulsoup4' – Dmitry

+0

我通過brew安裝了python3.6,並且找到最新版本的bs4:bs4.5.3,我安裝並替換了以前的版本bs4,但它仍然像之前一樣崩潰。 – Kath

回答

0

你應該升級你的beautifulsoup模塊,使用python 3.6的罰款。 從4.4.0開始,BeautifulSoup與Python 3.5兼容。和上述

pip3 install --upgrade beautifulsoup4

+0

https://www.crummy.com/software/BeautifulSoup/bs4/download/4.5/?C=M;O=A謝謝,但我下載了最新版本並安裝了python3和python2,它不起作用,我不知道爲什麼... – Kath

+0

轉到/usr/local/lib/python3.6/Scripts運行pip卸載beautifulsoup4然後再次安裝。但重要的是你應該在正確的目錄 – nuriselcuk

+0

中做到這一點!我採取你的方法並刪除舊文件,然後再次安裝。最後,它工作正常,謝謝大家。 – Kath