Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python 3.x ImportError: No module named 'cStringIO'

How do I solve an ImportError: No module named 'cStringIO' under Python 3.x?

like image 281
jvi Avatar asked Jan 28 '15 19:01

jvi


2 Answers

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() 
like image 98
Simeon Visser Avatar answered Sep 20 '22 08:09

Simeon Visser


I had the same issue because my file was called email.py. I renamed the file and the issue disappeared.

like image 23
Maeda Avatar answered Sep 24 '22 08:09

Maeda