FileNotFoundError: [Errno 2] File b'filepath.csv' does not exist: - python

I created a df to read a csv in my jupyter notebook library but for some reason the i'm getting an error like this:
FileNotFoundError: [Errno 2] File b'file path/filename.csv' does not exist: b'/file path/filename.csv'
My code is this:
df_csv = pd.read_csv('../file_path/file_name.csv', low_memory=False)
I believe I am using the absolute path to this file...I also checked the directory to confirm I was using the correct path.
import os
print(os.path.abspath('file_name.csv'))
and the output was:
/YXRwLW5vdGVib29rLW5pbmd1eWVuLXNlc3Npb24teGJ1YQ==/file_path/file_name.csv
Is that not the same as '../file_path/file_name.csv'? Would appreciate any troubleshooting tips...
I am not sure why this worked but instead of using the absolute path I used the relative path and just read the file name...A bit concerned with this method since I'd rather be explicit

Related

Having issues reading a .csv file present in a directory

I have a following path defined where I have
label_csv_file = r"C:/Users/username/Downloads/Personal Stuff/Python Directory files/Scripts/CSV Copy Scripts/label.csv"
I was trying to read the csv using pandas,
import pandas as pd
labelpd = pd.read_csv(label_csv_file)
I get the following error:
handle = open(
FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/username/Downloads/Personal Stuff/Python Directory files/Scripts/CSV Copy Scripts/label.csv', but the file is clearly there
I blacked out my name, instead of username my name is in the path, so I don't understand why I am having the issue, I have changed the label.csv to be just label as well. Its not just pandas, I was having issues opening with even with
open(label_csv_file, 'rb'),
where the label_csv_file path had been set, what is the issue here?
I have tried changing the file name to just label as it is already a .csv file that does not work either, I have changed the file path to just say /label, that doesn't work either

Python: FileNotFound Error. No such file or directory

I'm writing a program in which Python is unable to read my file despite of me posting the absolute file path with Pandas. The weirdest part is that this program has worked before but it just doesn't now, and I can't get to the bottom of why. Here is the program and error:
import pandas as pd
df = pd.read_csv(r"C:\Users\user\Desktop\Small_businesses1",encoding='latin1')
Error:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\user\\Desktop\\Small_businesses1'
The file is for sure at that very location, I copy pasted the location! Any fixes will be greatly appreciated
it seems that you have omitted the file type suffix try
df = pd.read_csv(r"C:\Users\user\Desktop\Small_businesses1.csv",encoding='latin1')

Python: "../DATA/file.csv" no longer working for file opening

Since a while, I have been using the short syntax ('../DAT/file.csv') to get to files under DATA folder. Since this morning, it is not working anymore and I am getting the following error:
FileNotFoundError: [Errno 2] No such file or directory: '../DATA/file.csv'
Any thoughts? Code I am using is below:
Thanks in advance,
df = pd.read_csv('../DATA/moviereviews.csv')
Check if your current directory is the one you expect it to be (i.e. the one that is beside the DATA directory). You can use the following to do so:
import os
print(os.getcwd())
Check that DATA/moviereviews.csv actually exists.

fp = builtins.open(filename, "rb") filenotfounderror: [errno 2] no such file or directory:

I want to load a whole folder of images together. I am working in R using Keras with python interface. I have set the path of the folder, then used the lapply function to load the images in the folder, one by one.
> files <- list.files(path="C:/Users/acer/Desktop/Triparna/traitestimage/Test/Bone/", pattern=".png",all.files=T, full.names=F, no.. = T)
> list_of_images = lapply(files, image_load)
The error :
Error in py_call_impl(callable, dots$args, dots$keywords) :
FileNotFoundError: [Errno 2] No such file or directory: 'bone58.png'
Detailed traceback:
File "C:\Users\acer\ANACON~1\envs\R-TENS~1\lib\site-
packages\keras\preprocessing\image.py", line 387, in load_img
img = pil_image.open(path)
File "C:\Users\acer\ANACON~1\envs\R-TENS~1\lib\site-
packages\PIL\Image.py", line 2548, in open
fp = builtins.open(filename, "rb")
Can you please help me. I understand the python interface is unable to identify the path. But how do I do that?
Convert it to path type; because it is not in path type when you're trying to access it.
Like if your path is:- "my_path/this_way"
Then:-
import os
path1 = os.path.normpath("my_path/this_way")
Now use path1.
Old question but had similar issue with keras::image_array_save
My workaround was using writeImage from package OpenImageR. Works very well.
You could use OpenImageR::readImage instead of image_load
Had the same problem using vs code on my MacBook, I was working with image files in multiple subfolders. So what I did was place the folder I am working with in the Users root folder of my mac where the program and the image resources were residing and run it from there and it worked. It turned out vs code was having problems finding the files when they were placed deep in multiple subfolders.FileNotFoundError solution

Little trouble in open files using python in Mac os

I have a CSV file in Documents , and I want to open it with python2.
I run this
print os.getcwd()
/Users/baicai
My file in /Users/baicai/Documents/blabla.csv
I run this get error
df= open('/Documents/blabla.csv')
IOError: [Errno 2] No such file or directory: '/Documents/blala.csv'
or this
f=open('/User/baicai/Documents/blabla.csv')
IOError: [Errno 2] No such file or directory: '/User/baicai/Documents/blabla.csv'
How to read? Thanks
df = open('Documents/blabla.csv') # remove leading /
With the leading /, the operating system thinks you want an absolute path as opposed to a relative path.
or
f=open('/Users/baicai/Documents/blabla.csv') # Users, not User
This one was just a typo :-)

Categories