根本无法导入Python的电子邮件模块

时间:2021-03-15 23:18:52

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.

我似乎无法导入电子邮件模块。每次我这样做都会出错。我已经尝试卸载Python并重新安装,但电子邮件模块只是拒绝工作。我甚至完成了“点击安装电子邮件”,它仍然被打破了。我使用的是Windows 7 Home Premium x64,运行x86版本的Python。

Here's what happens:

这是发生的事情:

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
>>>

EDIT: 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?

编辑:我已经尝试过python.org和ActivePython中的Python,认为ActivePython可能有效。反正有没有完全删除python及其所有数据,并开始100%新鲜可能吗?

5 个解决方案

#1


96  

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.

看起来你有一个名为email.py的文件。不要使用与Python标准库模块同名的文件名。通常,您的工作目录在Python搜索路径的早期版本中用于导入模块,因此工作目录中的文件将覆盖标准库中具有相同名称的模块。

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

By the way, this is a very common error. The excellent tutorial in the Python standard documentation set talks about it here.

顺便说一句,这是一个非常常见的错误。 Python标准文档集中的优秀教程在此处讨论它。

#2


28  

I just came across this error and wanted to share my solution. In my case, I had a file named email.py in directory. This created a name conflict between Python's email.py and my file. When smtplib tried to import email.utils it looked and my file and didn't find anything. After I renamed my copy of email.py into myemail.py everything worked like a charm.

我刚遇到这个错误,想分享我的解决方案。就我而言,我在目录中有一个名为email.py的文件。这在Python的email.py和我的文件之间产生了名称冲突。当smtplib试图导入email.utils它看起来和我的文件,但没有找到任何东西。在将我的email.py副本重命名为myemail.py后,一切都像魅力一样。

#3


4  

I also came across this error. In addition to renaming the email.py to something else, you must also remove the email.pyc (notice the C) file. After that, all is well. Thanks all!

我也遇到了这个错误。除了将email.py重命名为其他内容之外,还必须删除email.pyc(注意C)文件。在那之后,一切都很好。谢谢大家!

#4


1  

I also fetched this problem because i had a file named email.py in my project directory. I wasn't able to import urllib.request . When i changed the file name email.py to emailtest.py then the error gone away. In every time we should not use the name what is same as python core file name.

我也提到了这个问题,因为我的项目目录中有一个名为email.py的文件。我无法导入urllib.request。当我将文件名email.py更改为emailtest.py时,错误就消失了。在每次我们都不应该使用与python核心文件名相同的名称。

#5


-8  

npm install email

has fix my problem, try it.

解决了我的问题,试一试。

#1


96  

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.

看起来你有一个名为email.py的文件。不要使用与Python标准库模块同名的文件名。通常,您的工作目录在Python搜索路径的早期版本中用于导入模块,因此工作目录中的文件将覆盖标准库中具有相同名称的模块。

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

By the way, this is a very common error. The excellent tutorial in the Python standard documentation set talks about it here.

顺便说一句,这是一个非常常见的错误。 Python标准文档集中的优秀教程在此处讨论它。

#2


28  

I just came across this error and wanted to share my solution. In my case, I had a file named email.py in directory. This created a name conflict between Python's email.py and my file. When smtplib tried to import email.utils it looked and my file and didn't find anything. After I renamed my copy of email.py into myemail.py everything worked like a charm.

我刚遇到这个错误,想分享我的解决方案。就我而言,我在目录中有一个名为email.py的文件。这在Python的email.py和我的文件之间产生了名称冲突。当smtplib试图导入email.utils它看起来和我的文件,但没有找到任何东西。在将我的email.py副本重命名为myemail.py后,一切都像魅力一样。

#3


4  

I also came across this error. In addition to renaming the email.py to something else, you must also remove the email.pyc (notice the C) file. After that, all is well. Thanks all!

我也遇到了这个错误。除了将email.py重命名为其他内容之外,还必须删除email.pyc(注意C)文件。在那之后,一切都很好。谢谢大家!

#4


1  

I also fetched this problem because i had a file named email.py in my project directory. I wasn't able to import urllib.request . When i changed the file name email.py to emailtest.py then the error gone away. In every time we should not use the name what is same as python core file name.

我也提到了这个问题,因为我的项目目录中有一个名为email.py的文件。我无法导入urllib.request。当我将文件名email.py更改为emailtest.py时,错误就消失了。在每次我们都不应该使用与python核心文件名相同的名称。

#5


-8  

npm install email

has fix my problem, try it.

解决了我的问题,试一试。