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&#39;在一个新的.py文件上,它会给我同样的错误:
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
答案 0 :(得分:1)
我搜索了您的错误消息并想出了这个: https://bbs.archlinux.org/viewtopic.php?id=142036
看起来问题是Python正在尝试从本地源而不是自己的字符串库import from string
,因为你有一个类似命名的string.py
和/或string.pyc
文件你的工作目录。
尝试删除string.py和string.pyc文件,然后重新运行脚本。