How do I solve an ImportError: No module named 'cStringIO'
under Python 3.x?
python 3.x ImportError: No module named 'cStringIO'
Asked Answered
thx- accepting @SimonVissers solution. I should not have tried to install "email" it since it is available as a module. so just import email into code and make the changes to application code as needed. –
Agitato
This is a general issue when migrating to 3.x, and not just about installing any particular package e.g. email. –
Telekinesis
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()
io module exists in my python environment. but I am unable to install email itself which was my problem. i.e. "pip install email" fails. Am I supposed to hack into some code and make changes for it to install ? –
Agitato
@jvi: You should not install
email
, you should only import email
as it's part of the Python standard library. –
Pedate I had the same issue because my file was called email.py. I renamed the file and the issue disappeared.
I had the issue because my directory was called email
. I renamed the directory to emails
and the issue was gone.
© 2022 - 2024 — McMap. All rights reserved.