无法“导入 smtplib”

Cannot `import smtplib`

当我在 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

我有一个名为 "calendar.py" 的文件,它扰乱了我的 Python 环境,因为 smtplib 需要 calendar.py 才能工作。删除 calendar.py 解决了我的问题。

只是指出如何检测此类错误(因为它时常发生):

注意堆栈跟踪。在此示例中,可以在以下行中看到问题:

File "/Users/aaronblock/Documents/programming/scripts/calendar.py", line 7, in <module>

这肯定表明我们在尝试导入系统范围的库时导入了错误的文件。