Reputation: 21
i'm writing a software that reads a csv file at after some steps creates another csv file as output, the software is working fine but when i try to create an executable with pyinstaller i have an error saying that my software can't find the input csv file. Here is how i am reading the csv file as input, i've also tryed to change the pathname with no luck:
import pandas as pd
def lettore():
RawData = pd.read_csv('rawdata.csv', sep=';')
return RawData
how can i solve the problem?
Upvotes: 2
Views: 1079
Reputation: 881
Your code searches for the file it the same folder where the exe is launched.
It is equivalent to
import os
import pandas
filepath = os.path.join(os.getcwd(), 'filename.csv')
df = pd.read_csv(filepath)
Do not use relative paths when you create an exe.
I can give you two other options:
input
to get the right file path when running the exe (or eventually use argparse).filepath = input("insert your csv: ")
df = pd.read_csv(filepath)
Edit: after reading your comment, see also
How to reliably open a file in the same directory as a Python script
Upvotes: 1