When I try to load a workbook in Python 3.3 using openpyxl, I get a "No module named 'StringIO'" error:
In [5]: load_workbook(FileName)
Traceback (most recent call last):
File "<ipython-input-6-c4f3bc35f522>", line 1, in <module>
load_workbook(FileName)
File "C:\WinPython-64bit-3.3.2.3\python-3.3.2.amd64\lib\site-packages\openpyxl-1.6.2-py3.3.egg\openpyxl\reader\excel.py", line 112, in load_workbook
f = repair_central_directory(filename, is_file_instance)
File "C:\WinPython-64bit-3.3.2.3\python-3.3.2.amd64\lib\site-packages\openpyxl-1.6.2-py3.3.egg\openpyxl\reader\excel.py", line 59, in repair_central_directory
from StringIO import StringIO
ImportError: No module named 'StringIO'
I am aware that StringIO is not available in Python 3, but then again, I am using the py3.3 version of openpyxl (or so I think...?). However, when I try to find the file that calls StringIO, it is not in the directory noted in the traceback. Have I installed something incorrectly? Or is something else going on here?
Thanks in advance.
This should have been resolved in openpyxl 1.7
Related
I'm writing a script in Python 3.6 that uses the Avro module to parse some ADS-B messages, which means I'll be using the avro.datafile.DataFileReader function. The problem is that when I import DataFileReader like this:
from avro.datafile import DataFileReader at the top of my script, I'm met with:
Traceback (most recent call last):
File "reader.py", line 1, in <module>
from avro.datafile import DataFileReader
File "/home/user/.local/lib/python3.6/site-packages/avro/datafile.py", line 33, in <module>
from StringIO import StringIO
ModuleNotFoundError: No module named 'StringIO'
From What's New in Python 3.0, I see "the StringIO and cStringIO modules are gone. Instead, import the io module and use io.StringIO or io.BytesIO for text and data respectively."
This is where I'm stuck. Should I modify the avro module source code to make it python3-compatible?
NOTE: I installed avro using pip3.6 install avro-python3, so the module believes it is python3-compatible.
I am using ubuntu and as a result unable to use ms excel.Anyways I have created a spread sheet and I wish to make use of it in my python program.
Following is the Python program.
import pandas as pd
df=pd.read_excel("/home/files/file1.ods")
df.head()
Traceback (most recent call last):
File "spreadsheet.py", line 2, in <module>
df=pd.read_excel("/home/files/file1.ods")
File "/usr/lib/python3/dist-packages/pandas/io/excel.py", line 163, in read_excel
io = ExcelFile(io, engine=engine)
File "/usr/lib/python3/dist-packages/pandas/io/excel.py", line 187, in __init__
import xlrd # throw an ImportError if we need to
ImportError: No module named 'xlrd'
Does it mean that I have to use ms excel or is there an error in my understanding.Whatever be the case your help will be highly appreciated.
In recent versions (since 0.25) of Pandas, this feature is provided.
Just install the odfpy package (with pip install odfpy or etc) and then use pandas' (sadly) read_excel() function with the engine='odf' option. For example:
pd.read_excel('path_to_file.ods', engine='odf')
See https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#opendocument-spreadsheets.
I am using mechanize for the first time. If I type the line from mechanize import Browserin python shell (interpreter) it doesn't give any error but when run the same code as a part of a .py file it gives the following error:
Traceback (most recent call last):
File "/home/namit/Codes/BS4/mechanize.py", line 1, in <module>
import mechanize
File "/home/namit/Codes/BS4/mechanize.py", line 4, in <module>
mech = mechanize.Browser()
AttributeError: 'module' object has no attribute 'Browser'
Change your filename from mechanize.py. Python is importing your file as the module, instead of importing the mechanize library.
Rename your filename to something other than mechanize.py
Giving files names same as that of the modules imported causes the file to be imported instead of the intended module.
I unzipped xlwt and tried to install from that directory, but I get the following error.
>> python setup.py install
Traceback (most recent call last):
File "setup.py", line 4, in <module>
from xlwt import __VERSION__
File "C:\Users\mypc\Desktop\xlwt-0.7.5\xlwt\__init__.py", line 3, in <module>
from Workbook import Workbook
ImportError: No module named 'Workbook'
Here's the init.py that's giving the error
__VERSION__ = '0.7.5'
from Workbook import Workbook
from Worksheet import Worksheet
from Row import Row
from Column import Column
from Formatting import Font, Alignment, Borders, Pattern, Protection
from Style import XFStyle, easyxf, easyfont, add_palette_colour
from ExcelFormula import *
Anyone know what's causing this error? I need xlwt to write to excel spreadsheets!
xlwt is Python 2.x compatable, and does not seem to work on Python 3.x. "xlwt-future" is a fork of xlwt that works for Python 3:
pip install xlwt-future
I just installed a different version of xlwt and it worked.
i am using "import xlwt" to create new excel sheet but it is throwing the following error?
Traceback (most recent call last):
File "xl.txt", line 1, in
import xlwt
ImportError: No module named xlwt
How to solve this problem ?
You need to install package xlwt.
You will get the package here