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

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

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

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.

Related

How can I install parse for python3 if I get importError?

So I'm working in Linux and I need to install parse for python3 but always get the same error: ImportError: No module named parse. I tried it:
from urllib.parse import urlparse
from parser import *
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse (but as I know its only for python2, I work on python3).
Also tried to do this pip install parse but had no result. Before it I had the next error “NameError: global name 'parse' is not defined”.
Please can you help me, what should I do? I found that some people have the same problem but their resolutions dont help me
urllib is in standard library, no need to install. It works ok for me in python 3.x. Probably you have named your script(the .py file you are running) to urllib. This is a common mistake, rename it to something else then it works.
It could happen even if you have a python file named urllib in your directory... because when you run your script, python will automatically add it's directory to sys.path(where python searched for modules/packages). So it gets reached sooner than the original urllib which is in the standard library.
Search that file in your directory and delete it.

ModuleNotFoundError: No module named 'copy_reg\r'

I am trying to execute a python code in my Windows Machine where I have imported pickle and I have loaded the file but for some reason, it is giving this error called ModuleNotFound and I don't know what does pickle has to do anything with 'copy_reg\r'
Here goes my code:
from six.moves import cPickle
def openfile(basename):
with open(os.path.join(DIR_PATTERNS, basename), 'rb') as fh:
return cPickle.load(fh)
#return open(os.path.join(DIR_PATTERNS, basename), 'rb')
HAVE_FSAs = openfile("HAVE_FSAs.pickle")
Here goes the error:
HAVE_FSAs = cPickle.load(openfile("HAVE_FSAs.pickle"))
ModuleNotFoundError: No module named 'copy_reg\r'
I have already tried import pickle as cPickle but it did not work for me. All the variables are declared so it can't be that as well and moreover, I do not understand why is it giving ModuleNotFound
python3 have copyreg, no copy_reg . so you can correct Source Code, for example, you need delete code:
import copy_reg
then, you must replace:
import copyreg

ImportError: cannot import name 'deque' from 'collections' how to clear this?

I have get
ImportError: cannot import name 'deque' from 'collections'
How to resolve this issue? I have already changed module name (the module name is collections.py) but this is not worked.
In my case I had to change my import statement to
from collections import deque
and previously it was
from collections import Deque
I had the same problem when i run the command python -m venv <env folder>. Renamed my file from: collections.py to my_collections.py.
It worked!
In my case I had to rename my python file from keyword.py to keyword2.py.

Installing SOAPpy in Python 3

I'm trying to install SOAPpy library in python 3 . I get the following error
"/../Downloads/SOAPpy-0.11.6/SOAPpy/__init__.py", line 3, in <module>
from version import __version__
ModuleNotFoundError: No module named 'version'
I tried to install the other alternative that has been suggested in the other posts , e.g. zeep . But the url that I have to use has soap in it and is not working with the other alternatives.
The following is the example script that I am using from here
#!/usr/bin/python
import string
import hashlib
from SOAPpy import WSDL ## for extracting the URL of the endpoint (server script) from the WSDL file
from SOAPpy import SOAPProxy ## for usage without WSDL file
#1) Usage with WSDL (for extracting the URL of the endpoint)
wsdl = "https://www.brenda-enzymes.org/soap/brenda.wsdl"
password = hashlib.sha256("myPassword").hexdigest()
client = WSDL.Proxy(wsdl)
parameters = "j.doe#example.edu,"+password+",ecNumber*1.1.1.1#organism*Homo sapiens#"
resultString = client.getKmValue(parameters)
print resultString
I would like to ask for suggestions on how this can be resolved.
The version module is part of the SOAPpy package, but in Python 3 you'd need to use absolute imports,
from SOAPpy.version import __version__
or
from .version import __version__ in your __init__ installer package file.
There will be other issues with the code too.
Here's a link which supports SOAPpy for python3 https://pypi.org/project/SOAPpy-py3/

Not able to import ggplot in python 3.5

I have Ubuntu Gnome 16.04 both python 2.7 and python 3.5 installed.
I have installed ggplot in python 3.5 but not able to import it.
I am getting ImportError: No module named 'StringIO'.
Am I missing something? As far as I know StringIO module has been merged in io module in python 3.5.
Found the issue, some files have not been fully converted for python3.
Open file /usr/local/lib/python3.5/dist-packages/ggplot/ggplot.py and change
import StringIO
to this
from io import StringIO
I am not getting any error now but there could be some other files where python2 codes needs to be converted to work in python3.

Resources