I have a virtualenv running python 3.4.0 pip version is pip 1.5.4 I did pip install email and get the error: ImportError: No module named 'cStringIO' at the end of the process (which failed) How does one get the email package for python 3.4.0
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
From Python 3.0 changelog;
The StringIO and cStringIO modules are gone. Instead, import the io module and use io.StringIO or io.BytesIO for text and data respectively.
From the Python 3 email documentation it can be seen that io.StringIO
should be used instead:
from io import StringIO
from email.generator import Generator
fp = StringIO()
g = Generator(fp, mangle_from_=True, maxheaderlen=60)
g.flatten(msg)
text = fp.getvalue()
Reference: https://docs.python.org/3.4/library/io.html
回答2:
I had the same issue because my file was called email.py. I renamed the file and the issue disappeared.