Traceback (most recent call last): File "urlgrabber.py", line 1, in <module>
from bs4 import BeautifulSoup File "/Users/asdf/Desktop/Scraper/bs4/__init__.py", line 29, in <module>
from .builder import builder_registry File "/Users/asdf/Desktop/Scraper/bs4/builder/__init__.py", line 4, in <module>
from bs4.element import ( File "/Users/asdf/Desktop/Scraper/bs4/element.py", line 5, in <module>
from bs4.dammit import EntitySubstitution File "/Users/asdf/Desktop/Scraper/bs4/dammit.py", line 13, in <module>
import logging File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/__init__.py", line 28, in <module>
from string import Template ImportError: cannot import name 'Template'
我有代碼,基本上刮擦鏈接了一個網站。直到最近它才正常工作,它剛剛開始在命令提示符處返回此錯誤。我正在使用python 3.我已經下載了bs4並將其與python一起更新。我仍然收到這個錯誤。仍然是Python /編程新手,我不知道如何解決這個問題。我把上面的命令提示符的消息。之前的代碼是標準的刮碼,工作正常,但由於某種原因,最近沒有工作。我不能從BS4進口BeautifulSoup「有一個新的.py文件,它會給我同樣的錯誤:無法找出我的python 3腳本中的beautifulsoup4有什麼問題
File "bs4fml.py", line 1, in <module>
from bs4 import BeautifulSoup
File "/Users/asdf/Desktop/Scraper/bs4/__init__.py", line 29, in <module>
from .builder import builder_registry
File "/Users/asdf/Desktop/Scraper/bs4/builder/__init__.py", line 4, in <module>
from bs4.element import (
File "/Users/asdf/Desktop/Scraper/bs4/element.py", line 5, in <module>
from bs4.dammit import EntitySubstitution
File "/Users/asdf/Desktop/Scraper/bs4/dammit.py", line 13, in <module>
import logging
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/__init__.py", line 28, in <module>
from string import Template
工作目錄中是否存在string.py或string.pyc文件? – jinksPadlock
還是新的這個,但通過工作目錄你的意思是我試圖運行的文件夾下的文件夾?如果是這樣,是的,該文件夾中有一個string.py,但它只是垃圾代碼來測試一個片段。我刪除它,同樣的錯誤仍然出現。 –
是的,工作目錄是您執行代碼的目錄。您應該刪除string.py和string.pyc文件。發生什麼事是Python試圖導入你的字符串庫而不是它自己的。 – jinksPadlock