Python stopped recognizing my .xlsx files overnight

Hello! I am running into a very peculiar situation with python (3.8.8)… I have been using python for 3 years now and was working on some very basic code last night that involved reading excel files using pandas (1.2.4) - everything worked great. However, this morning, I woke up and ran the exact same code and I received an error from pandas suggesting that there was no such file or directory. I had not changed the file path since the night before and I am using the full file path in my code. I can even copy and paste this file path into my file explorer and the excel file will open up.

I tried debugging within pandas with no luck. I then decided to uninstall and reinstall Anaconda with no luck. I then upgraded versions of pandas to 1.3.0 with no luck. Then I tried downgrading to 1.2.3 with no luck. Then I uninstalled and reinstalled Anaconda just for fun with no luck.

Eventually I decided to see if python’s os library was able to recognize excel files that pandas wasn’t able to read in. Interestingly, whenever I used os.listdir(), every file in the folder showed up EXCEPT for the .xlsx files. I tried this with multiple directories and the result was consistent. Python does not seem to be recognizing my .xlsx files. So I decided to uninstall Anaconda and install a fresh version of python (3.9.6). I used the same os.listdir() code and got the same result - .xlsx files were nowhere to be found in the output.

I am so confused!! I have spent hours trying to debug this and I have not had any luck whatsoever. Does anybody happen to know why this could be happening? Any suggestions? Thank you all so much in advance!!

EDIT: After further debugging, I decided to try placing an excel file directly in my C:/ drive and python was able to recognize and read this file in. I then created a folder in this location, put the file in the folder, and I am still able to access the file. However, I am still unable to even recognize the file if it is in my user folder, where I have been accessing files without a problem up until this morning. This is a very inconvenient workaround, so if anybody has any input, I would still very much appreciate it.

Hi Chris,

I’m not sure where this myth about “reinstall Python” comes from :frowning:

Reinstalling should not be the first solution you try. It almost never
solves the problem – all you end up doing is wasting time, energy and
effort to delete a perfectly good installation and reinstall another
perfectly good installation that has the same issue. As you have

Python doesn’t recognise .xlsx files as anything special at all. They’re
just files.

You say you tried “debugging within pandas” – what did you do?

Please copy and paste the full test of the error message you get when
you run your code. No screenshots, don’t summarise it or retype it.

You say:

“I can even copy and paste this file path into my file explorer and the
excel file will open up.”

Great! That proves that the files are still there. So please copy and
paste the exact file path you use in the file explorer.

If you know the folder (directory) where the Excel files are supposed to
be, please run this code in the Python interpreter and show us the
output. (You can delete any personal or private files if you need to).

import os
import glob
directory = 'C:/my directory/'  # use the actual path instead
print(glob.glob(directory + '*.xlsx'))
print(glob.glob(directory + '*.XLSX'))

Hey Steven, thank you for your response.

As far as debugging within pandas, I tried using the engine=openpyxl solution that I saw on Stack Overflow. I suppose that is the extent that I debugged in pandas because once I discovered that these files weren’t showing up using os.listdir(), I assumed it could not be a pandas-specific issue.

The error I receive when using the full file path (the same file path that opens the file when copied and pasted into my file explorer):

FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/USER_NAME/Documents/Requests/Staffing Dashboard/SENSITIVE_FILE_NAME.xlsx'

Then, using the code you have provided, here is the output:

['Jupyter', 'naveens notes.txt']

There is definitely one .xlsx file in this folder that is not showing up. Thanks again for taking time to respond.

Have permissions changed? Are you running the Python code as a different
user, or with lower permissions, than the file explorer?

Are you absolutely sure that the pathnames are the same? Especially
check for extra or missing spaces, or backslashes that aren’t escaped.

How is the path defined in your script? Is it computed or a hard-coded

 PATHNAME = "C:/..."

Any non-ASCII characters in the path? Are there any shortcuts or links
in the path? Is it a local drive or network or remote?

Try this:

import os