当我在Python解释器中尝试import smtplib
时,我收到此错误:
ImportError: cannot import name fix_eols
我该如何解决这个问题?
编辑: 这是完整的堆栈跟踪:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 46, in <module>
import email.utils
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/utils.py", line 32, in <module>
from email._parseaddr import quote
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/_parseaddr.py", line 16, in <module>
import time, calendar
File "/Users/aaronblock/Documents/programming/scripts/calendar.py", line 7, in <module>
File "/usr/local/lib/python2.7/site-packages/apiclient/__init__.py", line 19, in <module>
from googleapiclient import discovery
File "/usr/local/lib/python2.7/site-packages/googleapiclient/discovery.py", line 38, in <module>
from email.generator import Generator
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/generator.py", line 15, in <module>
from email.header import Header
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/header.py", line 16, in <module>
import email.quoprimime
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/quoprimime.py", line 49, in <module>
from email.utils import fix_eols
ImportError: cannot import name fix_eols
答案 0 :(得分:3)
只是指出如何检测这种错误(因为它确实经常发生):
注意堆栈跟踪。在这个例子中,问题可以在以下行中看到:
File "/Users/aaronblock/Documents/programming/scripts/calendar.py", line 7, in <module>
当我们尝试导入系统范围的库时,它肯定表示导入了错误的文件。
答案 1 :(得分:0)
我有一个名为“calendar.py”的文件会混淆我的Python环境,因为smtplib需要calendar.py才能工作。删除calendar.py解决了我的问题。