Problem reading excel with last version of Pandas - python

Well, I recently bought a new computer and installed Spyder as well as Python, and updated the libraries up-to-date using pip. Everything works well except for Pandas when I try to import an excel file.
This is my code
import pandas as pd
filename = "sample_sheet.xlsx"
data = pd.read_excel(filename)
And this is the error I get
ImportError: Missing optional dependency 'xlrd'. Install xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd.
I have already installed xlrd as well as openpyxl with pip, and when trying to install it again it shows the following message
Requirement already satisfied: xlrd in c:\users\lucas\appdata\local\programs\python\python39\lib\site-packages (2.0.1)
I am not the only one with this error, a friend of mine has it too. Has anyone came up with a solution? Thank you in advance for your answers.

Just copy xlrd and openpypl files (or your complete site-packages folder, if you want) from Python folder into your user appdata, to the path where python is installed.
In your case, copy all content from C:\users\lucas\appdata\local\programs\python\python39\lib\site-packages to C:\Program Files\Python39\Lib\site-packages or C:\Python39, depending on where you have installed Python

Related

Trouble importing Tabulate with Python 3.7

I'm running Python 3.7 on Windows 10 and I keep getting No module named 'tabulate' error. I have deleted Python 2.
I've tried everything suggested in a similar question:
>> pip install tabulate
>> pip3 install tabulate
>> python -m pip install tabulate
All of the above respond with
>> Successfully installed tabulate-0.8.6
If I try to run it again, I get
>> Requirement already satisfied: tabulate in c:\program files\python37\lib\site-packages (0.8.6)
But I keep getting the same ModuleNotFoundError when I try to import it. What can I try still?
UPD:
I have double-checked whether old versions of Python were uninstalled, and to my surprise EVERYTHING was still there: the folders, the files, the paths in the PATH... I'm afraid that was the reason of my problems, but I won't be able to test it until later.
I solved this issue by updating tabulate to the latest version using:
pip install --upgrade tabulate

Python: Pandas pd.read_excel giving ImportError: Install xlrd >= 0.9.0 for Excel support

I am trying to read a .xlsx with pandas, but get the follwing error:
data = pd.read_excel(low_memory=False, io="DataAnalysis1/temp1.xlsx").fillna(value=0)
Traceback (most recent call last):
File "/Users/Vineeth/PycharmProjects/DataAnalysis1/try1.py", line 9, in <module>
data = pd.read_excel(low_memory=False, io="DataAnalysis1/temp1.xlsx").fillna(value=0)
File "/Users/Vineeth/venv/lib/python2.7/site-packages/pandas/util/_decorators.py", line 118, in wrapper
return func(*args, **kwargs)
File "/Users/Vineeth/venv/lib/python2.7/site-packages/pandas/io/excel.py", line 230, in read_excel
io = ExcelFile(io, engine=engine)
File "/Users/Vineeth/venv/lib/python2.7/site-packages/pandas/io/excel.py", line 263, in __init__
raise ImportError(err_msg)
ImportError: Install xlrd >= 0.9.0 for Excel support
I've also tried
data = pd.read_excel("DataAnalysis1/temp1.xlsx", low_memory=False).fillna(value=0)
And I Still get the same error.
Background: I'm trying to extract an excel file with multiple worksheets as a dict of data frames.I installed xlrd version 0.9.0 and the latest version(1.1.0) but I still get the same error. Thanks!
As #COLDSPEED so eloquently pointed out the error explicitly tells you to install xlrd.
pip install xlrd
And you will be good to go.
Since December 2020 xlrd no longer supports xlsx-Files as explained in the official changelog. You can use openpyxl instead:
pip install openpyxl
And in your python-file:
import pandas as pd
pd.read_excel('path/to/file.xlsx', engine='openpyxl')
Either use:
pip install xlrd
And if you are using conda, use
conda install -c anaconda xlrd
That's it. good luck.
If you are in ubuntu this work for me:
python3 -m pip install openpyxl
python3 -m pip install xlrd
This happened to me after I ran a script with cProfile a la python3 -m cProfile script.py even though xlrd was already installed and had never thrown this error before. it persisted even under python3 script.py. (Granted, I agree this wasn't what happened to OP, given the obvious import error)
However, for cases like mine, the following fixed the issue, despite being told "requirement already met" in every case.
pip install --upgrade pandas
pip install --upgrade xlrd
Pretty confounding stuff; not sure if cProfile was the cause or just a coincidence
The following should work, assuming your pip install operated on python2.
python3 -m pip install xlrd
I was getting an error
"ImportError: Install xlrd >= 1.0.0 for Excel support"
on Pycharm for below code
import pandas as pd
df2 = pd.read_excel("data.xlsx")
print(df2.head(3))
print(df2.tail(3))
Solution : pip install xlrd
It resolved error after using this.
Also no need to use "import xlrd"
This works for me:
For Python 3
pip3 install xlrd --user
For Python2
pip install xlrd --user
I don't know if this will be helpful for someone, but I had the same problem.
I wrote pip install xlrd in the anaconda prompt while in the specific environment and it said it was installed, but when I looked at the installed packages it wasn't there.
What solved the problem was "moving" (I don't know the terminology for it) into the Scripts folder of the specific environment and do the pip install xlrd there.
Hope this is useful for someone :D
Was getting the error while I was using jupyter.
ModuleNotFoundError: No module named 'xlrd'
...
ImportError: Install xlrd >= 0.9.0 for Excel support
it was resolved for me after using.
!pip install xlrd
I encountered same problem and took 2 hours to figure it out.
pip install xlrd (latest)
pip install pandas (latest)
Go to C:\Python27\Lib\site-packages and check for xlrd folder (if there are 2 of them) delete the old version
open a new terminal and use pandas to read excel. It should work.
I had the same problem and none of the above answers worked. If you go into the settings (CTRL + ALT + s) and search for project interpreter you will see all of the installed packages. Click the + button at the top right and search for xlrd, then click install package at the bottom left.
I had already done the "pip install xlrd" command from the file location of my python.exe before this, so you may need to do that as well. (you can find the file location by searching it in windows search bar and right click -> open file location, then type cmd into the file explorer address bar)
This can be because your required libraries are been installed in Python environment instead of Spyder.
https://github.com/spyder-ide/spyder/wiki/Working-with-packages-and-environments-in-Spyder
I had the same problem. Actually, the problem is that even after installing packages/libraries using pip these packages are not integrated with IDE. So, need to add libraries specifically to the ide.
First of all you need to install xlrd & pandas packages. Then try below code.
import xlrd
import pandas as pd
xl = pd.ExcelFile("fileName.xlsx")
print(xl.parse(xl.sheet_names[0]))
You need to install the "xlrd" lib
For Linux (Ubuntu and Derivates):
Installing via pip:
python -m pip install --user xlrd
Install system-wide via a Linux package manager:
*sudo apt-get install python-xlrd
Windows:
Installing via pip:
*pip install xlrd
Download the files:
https://pypi.org/project/xlrd/
Another possibility, is the machine has an older version of xlrd installed separately, and it's not in the "..:\Python27\Scripts.." folder.
In another word, there are 2 different versions of xlrd in the machine.
when you check the version below, it reads the one not in the "..:\Python27\Scripts.." folder, no matter how updated you done with pip.
print xlrd.__version__
Delete the whole redundant sub-folder, and it works. (in addition to xlrd, I had another library encountered the same)
I encountered a similar issue trying to use xlrd in jupyter notebook. I notice you are using a virtual environment and that was the key to my issue as well. I had xlrd installed in my venv, but I had not properly installed a kernel for that virtual environment in my notebook.
To get it to work, I created my virtual environment and activated it.
Then... pip install ipykernel
And then... ipython kernel install --user --name=myproject
Finally, start jupyter notebooks and when you create a new notebook, select the name you created (in this example, 'myproject')
Hope that helps.
Please make sure your python or python3 can see xlrd installation. I had a situation where python3.5 and python3.7 were installed in two different locations. While xlrd was installed with python3.5, I was using python3 (from python3.7 dir) to run my script and got the same error reported above. When I used the correct python (viz. python3.5 dir) to run my script, I was able to read the excel spread sheet without a problem.
As #WojciechJakubas mentioned to install openpyxl instead of xlrd, I used openpyxl and it worked.
pip install openpyxl
import openpyxl
path = "path to file.xlxs"
wb_obj = openpyxl.load_workbook(path)
sheet_obj = wb_obj.active
length_col = sheet_obj.max_row
print("Length of rows : ", length_col)
I hope it will help lot of people in 2023.

No module named 'xlrd' when xlrd module is installed

I am using Jupyter Notebook in an environment, and when I try to use xlrd module I get "No module named 'xlrd". I checked others Stack Overflow posts and I installed the module xlrd using the command pip3 install xlrd. but still it continues to throw me the error No module named 'xlrd.
I tried again to install may be something went wrong and I get Requirement already satisfied: xlrd in /usr/local/lib/python3.6/site-packages which I believe it's ok. Is it possible that I have to update my environment in order to use the new installs? If so how do I do it?

No module named openpyxl - Python 3.6 - OSX

I've installed openpyxl from the Terminal using
pip3 install openpyxl
without any problems. I've even double-checked by simply running import openpyxl from the Terminal window once Python is running, and it imports no problem.
The problem starts when I try and import openpyxl from a script I'm building to work with a spreadsheet. I'm using Sublime Text and can't even get past the import openpyxl at the beginning of the script without running into the following error:
Traceback (most recent call last):
File "/Users/wcw/Desktop/test.py", line 1, in
import openpyxl
ImportError: No module named openpyxl
How can this be happening? I know I've installed openpyxl correctly from the Terminal window without any errors so how can my script not find the module?
Try to do:
pip3 install --user openpyxl
Doing the --user worked for me when I tried to run my .py files with matplot lib modules which worked in 3.5 but not in 3.6.
I have the same problem.
I've installed the openpyxl succesfully via Anaconda
!pip3 install --upgrade openpyxl
Collecting openpyxl Using cached
https://files.pythonhosted.org/packages/95/8c/83563c60489954e5b80f9e2596b93a68e1ac4e4a730deb1aae632066d704/openpyxl-3.0.3.tar.gz
Requirement already satisfied, skipping upgrade: jdcal in
/Users/a18301335/Library/Python/3.8/lib/python/site-packages (from
openpyxl) (1.4.1) Requirement already satisfied, skipping upgrade:
et_xmlfile in
/Users/a18301335/Library/Python/3.8/lib/python/site-packages (from
openpyxl) (1.0.1) Installing collected packages: openpyxl Found
existing installation: openpyxl 1.8.6
Uninstalling openpyxl-1.8.6:
Successfully uninstalled openpyxl-1.8.6 Running setup.py install for openpyxl ... done Successfully installed openpyxl-3.0.3
But when I try to use tat library I get an error No module named openpyxl
import openpyxl
ModuleNotFoundError: No module named 'openpyxl'
If I try to import openpyxl in Terminal, I don't have the error. What's wrong?
This may be overly simplistic, but I had the same problem. I installed the module successfully but import openpyxl resulted in an error. I needed to close IDLE and start a new session. After that, my import command worked just fine.

cannot import workbook in openpyxl

I have installed openpyxl in ubuntu.
now I am running the openpyxl with xlsx files.
While importing the module, it gives me the following error.
from openpyxl import Workbook
ImportError: cannot import name Workbook
Can anyone knows what I have to do to solve the problem?
I think you want:
from openpyxl import workbook # not Workbook
Note the capitalization of the name here.
I answer your second problem, because I found the solution (as though the cause of the first one is the same).
I think the problem is caused because the version that you have installed on your Ubuntu is not the latest version (1.5.7 at the moment). And the official documentation is based on the latest one.
For example the version of openpyxl provided on my Ubuntu 11.10 is not the latest, but 1.5.3, and if you use this syntax (taken from here: https://bitbucket.org/ericgazoni/openpyxl/wiki/Home), the commands work:
from openpyl.workbook import Workbook
for the Workbook and for load_workbook:
from openpyxl.reader.excel import load_workbook
But you can also install the latest one with easy_install:
$ sudo easy_install openpyxl
And to install easy_install, read this answer: https://askubuntu.com/questions/27519/can-i-use-easy-install
Actually latest version openpyxl not working well for load_workbook for python2.7 version . so just uninstall openpyxl by command --> pip uninstall openpyxl .
then reinstall openpyxl by giving providing version of same, works for me
pip install openpyxl=2.5.3 works

Categories