when i write import StringIO it says there is no such module.
From What’s New In Python 3.0:
The
StringIOandcStringIOmodules are gone. Instead, import theiomodule and useio.StringIOorio.BytesIOfor text and data respectively.
.
A possibly useful method of fixing some Python 2 code to also work in Python 3 (caveat emptor):
try:
from StringIO import StringIO ## for Python 2
except ImportError:
from io import StringIO ## for Python 3
Answer from Brent Bradburn on Stack OverflowNote: This example may be tangential to the main issue of the question and is included only as something to consider when generically addressing the missing
StringIOmodule. For a more direct solution the messageTypeError: Can't convert 'bytes' object to str implicitly, see this answer.
» pip install csv342
python - How do you use StringIO in Python3 for numpy.genfromtxt()? - Stack Overflow
Python 3.x support (ImportError: No module named 'StringIO')
pip - Python pip3 install StringIO Not Found for url: https://pypi.org/simple/stringio/ - Stack Overflow
python - no module named StringIO - Stack Overflow
when i write import StringIO it says there is no such module.
From What’s New In Python 3.0:
The
StringIOandcStringIOmodules are gone. Instead, import theiomodule and useio.StringIOorio.BytesIOfor text and data respectively.
.
A possibly useful method of fixing some Python 2 code to also work in Python 3 (caveat emptor):
try:
from StringIO import StringIO ## for Python 2
except ImportError:
from io import StringIO ## for Python 3
Note: This example may be tangential to the main issue of the question and is included only as something to consider when generically addressing the missing
StringIOmodule. For a more direct solution the messageTypeError: Can't convert 'bytes' object to str implicitly, see this answer.
In my case I have used:
from io import StringIO
I think you're looking for the io module in Python 3.x. cStringIO (which is a Python 2 module that is a faster version of StringIO, see here) was replaced with io, along with a host of other changes. See here for more info about that.
Historical note: Here is the reason why we no longer have both cStringIO and StringIO:
A common pattern in Python 2.x is to have one version of a module implemented in pure Python, with an optional accelerated version implemented as a C extension; for example, pickle and cPickle. This places the burden of importing the accelerated version and falling back on the pure Python version on each user of these modules. In Python 3.0, the accelerated versions are considered implementation details of the pure Python versions. Users should always import the standard version, which attempts to import the accelerated version and falls back to the pure Python version. The pickle / cPickle pair received this treatment. The profile module is on the list for 3.1. The StringIO module has been turned into a class in the io module. (Source)
Use this one:
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
Hello,
I'm trying to deploy on Heroku and make it work with AWS S3, but turns out it can't properly import boto or django-storages. I've learned that django-storages-redux solves the StringIO import error of Python 3; it works on my development machine, but it's not imported properly when I run the shell on Heroku. Boto, django-storages, and django-storages-redux are in the requirements.txt and are displayed when using pip list.
from django.core.files.storage import default_storage # this works
default_storage.exists('test') # returns False on my dev machine, errors on HerokuEDIT: Apparently Heroku does some weird thing, where the traceback shows ImportError of StringIO from s3boto.py, line 9, but according to this that line should've been changed already.
EDIT: Turns out it had to do something with the installed packages being cached; the solution was to change runtime.txt to refresh the whole thing, as suggested here.

