Python 3.4 : cStringIO vs. StringIO - python-3.x

QUESTION
I am returning an ImportError: No module named 'cStringIO'. Unfortunately cStringIO doesn't exist anymore and I need to use StringIO as a replacement. How can I do this?
import edgar
import ftplib
from io import StringIO
ftp = ftplib.FTP(edgar.FTP_ADDR)
ftp.login()
try:
edgar.download_all(ftp, "/tmp")
except Exception as e:
print(e)
finally:
ftp.close()
OUTPUT
Traceback (most recent call last):
File "/usr/local/lib/ana/lib/python3.4/site- packages/edgar/downloader.py", line 5, in <module>
from cStringIO import StringIO
ImportError: No module named 'cStringIO'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/aranjohn/PycharmProjects/edgar/secEd.py", line 1, in <module>
import edgar
File "/usr/local/lib/ana/lib/python3.4/site- packages/edgar/__init__.py", line 1, in <module>
from .downloader import FTP_ADDR, file_list, download, download_all
File "/usr/local/lib/ana/lib/python3.4/site- packages/edgar/downloader.py", line 7, in <module>
from StringIO import StringIO
ImportError: No module named 'StringIO'
Process finished with exit code 1

StringIO no longer exists in 3.x. Use either io.StringIO for text or io.BytesIO for bytes.

Related

beautiful soup not working when i run it for the first time

Traceback (most recent call last):
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\dammit.py", line 28, in <module>
import cchardet as chardet_module
ModuleNotFoundError: No module named 'cchardet'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\dammit.py", line 33, in <module>
import chardet as chardet_module
ModuleNotFoundError: No module named 'chardet'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/emwod/AppData/Local/Programs/Python/Python310/scrape.py", line 1, in <module>
import bs4 as bs
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\__init__.py", line 37, in <module>
from .builder import (
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\builder\__init__.py", line 9, in <module>
from bs4.element import (
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\element.py", line 19, in <module>
from bs4.formatter import (
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\formatter.py", line 1, in <module>
from bs4.dammit import EntitySubstitution
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\dammit.py", line 37, in <module>
import charset_normalizer as chardet_module
ValueError: source code string cannot contain null bytes
=== RESTART: C:/Users/emwod/AppData/Local/Programs/Python/Python310/scrape.py ==
Traceback (most recent call last):
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\dammit.py", line 28, in <module>
import cchardet as chardet_module
ModuleNotFoundError: No module named 'cchardet'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\dammit.py", line 33, in <module>
import chardet as chardet_module
ModuleNotFoundError: No module named 'chardet'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/emwod/AppData/Local/Programs/Python/Python310/scrape.py", line 1, in <module>
from bs4 import BeautifulSoup as bs
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\__init__.py", line 37, in <module>
from .builder import (
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\builder\__init__.py", line 9, in <module>
from bs4.element import (
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\element.py", line 19, in <module>
from bs4.formatter import (
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\formatter.py", line 1, in <module>
from bs4.dammit import EntitySubstitution
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\dammit.py", line 37, in <module>
import charset_normalizer as chardet_module
ValueError: source code string cannot contain null bytes
I was trying to start bs4 but this happend
ModuleNotFoundError: No module named 'cchardet'
Seems not to be a strict BeautifulSoup topic - A module is missing, so you should install it or put it in path if you like to use it:
pip install cchardet
*Not sure if you need cchardet for your task, so some improvment of question would be great. Take a read: How to create mcve.

Import Image Module error while generating qrcode

I installed qrcode 7.3.1 and Image 1.5.33. Pillow 9.0.0 is also installed during Image install. But while running following example from qrcode documentation
import qrcode
img = qrcode.make('Some data here')
type(img) # qrcode.image.pil.PilImage
img.save("some_file.png")
Following error generates
Traceback (most recent call last):
File "C:\****\venv\lib\site-packages\qrcode\image\pil.py", line 5, in <module>
from PIL import Image, ImageDraw
File "C:\****\venv\lib\site-packages\PIL\Image.py", line 30, in <module>
import logging
File "C:\****\himal\anaconda3\lib\logging\__init__.py", line 26, in <module>
import sys, os, time, io, re, traceback, warnings, weakref, collections.abc
File "C:\****\anaconda3\lib\traceback.py", line 5, in <module>
import linecache
File "C:\****\anaconda3\lib\linecache.py", line 11, in <module>
import tokenize
File "c:\users\himal\anaconda3\lib\tokenize.py", line 35, in <module>
from token import EXACT_TOKEN_TYPES
ImportError: cannot import name 'EXACT_TOKEN_TYPES' from 'token' (***\token.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\****\scan_qrcode.py", line 2, in <module>
img = qrcode.make('Some data here')
File "C:\****\venv\lib\site-packages\qrcode\main.py", line 13, in make
return qr.make_image()
File "C:\****\venv\lib\site-packages\qrcode\main.py", line 296, in make_image
from qrcode.image.pil import PilImage
File "C:\****\venv\lib\site-packages\qrcode\image\pil.py", line 7, in <module>
import Image
ModuleNotFoundError: No module named 'Image'
Python 3.8 is current python version.

AttributeError: module 'typing' has no attribute 're' in pandas Python 3.7

I can't import pd from pandas because i have this error. I search on google but I didn't find the fix for this..
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python37\lib\site-packages\pandas\__init__.py", line 23, in <module>
from pandas.compat.numpy import *
File "C:\Python37\lib\site-packages\pandas\compat\__init__.py", line 431, in <module>
re_type = typing.re.Pattern
AttributeError: module 'typing' has no attribute 're'
I think this is changing underneath us as Python's typing module matures, but in our case, the issue was that we did from Typing import re, and then later did something like:
def funct(some_re: re.Pattern):
The fix was dumb. Simply change your import to be from typing import Pattern and then do:
def funct(some_re: Pattern):
Bleh. Warts.

ImportError: No module named url

when i run the the given code in prepare_dataset.py whose code is below as
from urllib.request
import urlopen
import json as simplejson
def main():
# Download and prepare datasets
list_generator = video_list_generator.Generator("playlists.json", youtube_api_client.Client("AIzaSyD_UC-FpXbJeWzPfscLz9RhqSjKwj33q6A"))
video_list = list_generator.get_video_list("piano")
downloader = youtube_video_downloader.Downloader()
downloader.download_from_list(video_list)
if __name__ == '__main__':
main()
as python prepare_dataset.py in command-line then i get these errors
Traceback (most recent call last):
File "prepare_dataset.py", line 1, in <module>
from urllib.request import urlopen
ImportError: No module named request
How can i get to run the above file any idea guys?

"Licences" module not found by xlrd

I've installed xlutils and am trying the following code:
from xlrd import open_workbook
input_file = open_workbook('DataTestFile.xlsx')
for s in input_file.sheets():
print('Sheet:',s.name)
for row in range(s.nrows):
values = []
for col in range(s.ncols):
values.append(s.cell(row,col).value)
print(','.join(values))
print()
(as per tutorial book found here)
I'm getting an error indicating that the licences module is not found:
Traceback (most recent call last):
File "C:\Users\xxxxxxx\workspace_python\xxxxxxx\TestPack\test_file_excel.py", line 7, in <module>
from xlrd import open_workbook
File "C:\Python34\lib\site-packages\xlrd\__init__.py", line 9, in <module>
import licences
ImportError: No module named 'licences'
However, I can confirm that the file licences.py is present in the same folder as file _ init _.py quoted above:
How come it's not recognized?

Resources