问题描述
我似乎根本无法导入电子邮件模块。每次我做,我得到一个错误。我已经尝试卸载Python并重新安装,但电子邮件模块拒绝工作。我甚至做了点安装电子邮件,它还是坏了。我在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:\Users\Nicholas\Desktop>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:\Python27\lib\smtplib.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:\Python27\lib\smtplib.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的电子邮件模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!