问题描述
我似乎根本无法导入电子邮件模块.每次我这样做时都会出错.我试过卸载 Python 并重新安装,但电子邮件模块只是拒绝工作.我什至完成了pip install email",但它仍然坏了.我使用的是 Windows 7 Home Premium x64,运行的是 x86 版本的 Python.
I can't seem to import the email module at all. Every time I do it I get an error. I've tried uninstalling Python and reinstalling, but the email module just refuses to work. I've even done "pip install email" and it's still broken. I'm on Windows 7 Home Premium x64, running an x86 version of Python.
这是发生了什么:
c:UsersNicholasDesktop>python
ActivePython 2.7.2.5 (ActiveState Software Inc.) based on
Python 2.7.2 (default, Jun 24 2011, 12:21:10) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import email
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "email.py", line 1, in <module>
import smtplib
File "C:Python27libsmtplib.py", line 46, in <module>
import email.utils
ImportError: No module named utils
>>>
我已经尝试过 python.org 和 ActivePython 中的 Python,认为 ActivePython 可能有用.无论如何要完全删除python及其所有数据并开始100%新鲜?
I've tried both Python from python.org and ActivePython, thinking ActivePython might work. Is there anyway to completely remove python and all its data and start 100% fresh maybe?
推荐答案
看起来您有一个名为 email.py
的文件.不要使用与 Python 标准库模块同名的文件名.通常,您的工作目录位于用于导入模块的 Python 搜索路径的较早位置,因此您工作目录中的文件将覆盖标准库中具有相同名称的模块.
It looks like you have a file named email.py
. Don't use file names that have the same name as Python standard library modules. Generally, your working directory comes earlier on the Python search path for importing modules so files in your working directory will override modules with the same name in the standard library.
线索:注意回溯中的路径名
The clue: note the path names in the traceback
File "email.py", line 1, in <module>
import smtplib
File "C:Python27libsmtplib.py", line 46, in <module>
import email.utils
顺便说一下,这是一个非常常见的错误.Python 标准文档集中的优秀教程在这里一>.
By the way, this is a very common error. The excellent tutorial in the Python standard documentation set talks about it here.
这篇关于根本无法导入 Python 的电子邮件模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!