I'm doing a program responsible for managing a bookstore and I'm at the end of it. I'm creating the executable from it, but it's giving an error when running I don't know what it is.
Error:
Traceback (most recent call last):
File "main.py", line 3494, in <module>
File "db_manager.py", line 278, in titulo_livros
File "pandas\io\parsers.py", line 605, in read_csv
File "pandas\io\parsers.py", line 457, in _read
File "pandas\io\parsers.py", line 814, in __init__
File "pandas\io\parsers.py", line 1045, in _make_engine
File "pandas\io\parsers.py", line 1862, in __init__
File "pandas\io\parsers.py", line 1357, in _open_handles
File "pandas\io\common.py", line 642, in get_handle
FileNotFoundError: [Errno 2] No such file or directory: 'livros.csv'
[432] Failed to execute script main
The command I am using to generate the exe file is "pyinstaller --onefile main.py".
And that is my tree folder:
Please help me, i have no idea of what is going on.
Thank you very much in advance.
somewhere you are doing pandas.read_csv(fname)
where fname='livros.csv'
you need to give it the right path to the csv (or bundle the csv into the executable ... but that probably doesnt make sense, im not sure why you would ever bundle the csv into the executable)
after alot of back and forth I think this is what you want
import os
import pandas
import sqlalchemy
from sqlalchemy import create_engine
db_path = os.path.expanduser('~/my_file.db')
engine = create_engine('sqlite:///'+db_path, echo=False)
try:
existing = pandas.read_sql('SELECT title, author FROM books', engine)
except:
existing = pandas.DataFrame({'title':['Title 1','Title 2'],'author':['Bob Roberts','Sam Spade']})
print("DBPATH:",db_path)
# ... do some stuff (add/edit/remove items from your dataframe)
existing.to_sql("books",engine)