Pyinstaller application not working for file input, gives RuntimeError: input(): lost sys.stdin

Viewed 455

I have created a simple data analysis program that takes input from the user of a file name (with.csv extension) and outputs a graph. This has worked fine on my IDE before I used pyinstaller to try make it into an application (I have tried both the basic command pyinstaller my_script_name.py as well as pyinstaller --onefile my_script_name.py)

Now that I have created the applications, I get an "unhandled exception: input(): lost sys.stdin". I assume this is because the program is trying to read a file that is not included in the program/directory. I have also tried adding all .dll files using --add-data but with no luck.

My issue here is that I want the application to take a user input for the file name, read that file into the program, then create the graphic outputs with matplotlib. It seems like everything should work based on other answers I have found (all dependencies appear to be included in the build folder as well). I think the issue lies with taking the user input for the file and I can't figure out how to get around this.

Here is my code:

import pandas as pd
import matplotlib.pyplot as plt

while True:
    try:
        print("This program analyses data from the T1_Elec and T1_Seb directories only")
        print("Please input name of CSV file for analysis (including extension, i.e., file.CSV): ")
        file = input()
        data_file = pd.read_csv(file)
        break
    except FileNotFoundError:
        print("\nFILE NOT FOUND, please try again")
        pass

Active = data_file['Active Power']
time = data_file['Time']
date = data_file['Date'].iloc[2]

fig, ax = plt.subplots(figsize=(8, 7.5), dpi=80)
ax.plot(time, Active)
ax.set(xlabel="Time", ylabel="Active Power", title="Active Power Variation for " + date)
if len(time) > 100:
    ax.set_xticks(time[::60])
else:
    ax.set_xticks(time[::4])
plt.xticks(rotation=45, ha='right')
plt.grid()
plt.show()

Any help would be greatly appreciated. I have a feeling this could be a simple fix, I just can't think of it or find anything online.

Thanks in advance for your input!

0 Answers
Related