Python 为什么我收到错误:没有名为“email.MIMEMultipart”的模块?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39541394/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why am I getting the error: No module named 'email.MIMEMultipart'?
提问by daavidm
I'm trying to experiment with simple code to send an email from a Python script. I keep getting an error that the module 'email.MIMEMultipart' does not exist. To simplify the question/answer process, I can narrow it down even further. From the Python environment prompt I can enter
我正在尝试使用简单的代码从 Python 脚本发送电子邮件。我不断收到模块“email.MIMEMultipart”不存在的错误。为了简化问答过程,我可以进一步缩小范围。从Python环境提示我可以输入
>>>import email
>>>导入邮箱
>>> dir(email)
>>> 目录(电子邮件)
It will list a bunch of modules in the email module, but none of the MIME modules are there. I can see them from WindowsExplorer in the same lib folder as all the other modules. After searching other questions I did see that I had named my test program 'email.py' which I see now is a big no-no. I deleted it and verified there isn't also an 'email.pyc'.
它会在 email 模块中列出一堆模块,但没有一个 MIME 模块在那里。我可以在与所有其他模块相同的 lib 文件夹中从 WindowsExplorer 看到它们。在搜索其他问题后,我确实看到我将我的测试程序命名为“email.py”,我现在看到这是一个很大的禁忌。我删除了它并确认没有“email.pyc”。
I'm using Windows 10, Python 3.5.2. I've also already reinstalled Python with no improvement.
我使用的是 Windows 10,Python 3.5.2。我也已经重新安装了 Python,但没有任何改进。
Can anyone tell me what else I should check? This is the actual code:
谁能告诉我我还应该检查什么?这是实际的代码:
import smtplib
from email.MIMEMultipart import MIMEMultipart
回答by TessellatingHeckler
from email.MIMEMultipart import MIMEMultipart
Is the correct import for Python 2.x.
是 Python 2.x 的正确导入。
According to the Python 3 examples in the documentation (email), you need:
根据文档(电子邮件)中的 Python 3 示例,您需要:
from email.mime.multipart import MIMEMultipart