从 pyinstaller 生成的可执行文件不起作用

executable generated from pyinstaller it's not working

我正在做一个负责管理书店的程序,我已经完成了。我正在从它创建可执行文件,但是当 运行 我不知道它是什么时它给出了一个错误。

错误:

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

我用来生成exe文件的命令是“pyinstaller --onefile main.py”。

那是我的树文件夹:

my tree folder project

请帮助我,我不知道发生了什么。

非常感谢您。

你正在做的某处 pandas.read_csv(fname) 其中 fname='livros.csv'

你需要给它正确的 csv 路径(或将 csv 捆绑到可执行文件中......但这可能没有意义,我不确定你为什么要将 csv 捆绑到可执行文件中)

经过很多来回我想这就是你想要的

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)