包括多个文件夹以使用 pyinstaller 制作独立可执行文件

问题描述 投票:0回答:0

我正在尝试从我的 python 项目创建一个独立的可执行文件,但我无法使其工作。以下是完整的细节....

我的项目结构看起来像这样(在项目根目录中)

csab:
  2022:
    round1:
      some_files.csv
tool.py

因为我想从它创建独立的可执行文件,而我需要那些 csv 文件,因为它包含我的程序所需的数据,所以我为此目的使用了

pyinstaller

在 Windows 上,我尝试执行以下命令。

pyinstaller --noconfirm --onefile --console --add-data "E:/python/jee_counsellor/csab;csab/" --add-data "E:/python/jee_counsellor/josaa;josaa/"  "E:/python/jee_counsellor/tool.py"

在 Linux 上,我试过这个

python -m PyInstaller --onefile --add-data 'csab/*:csab' --add-data 'josaa/*:josaa' --exclude-module _tkinter tool.py

但是它们似乎都不起作用,因为它无法正确找到我的 csv 路径。 这是错误的详细信息(在 linux 和 windows 上都一样)

Traceback (most recent call last):
  File "tool.py", line 250, in <module>
  File "tool.py", line 16, in pre_setup
  File "tool.py", line 36, in csab_rounds
  File "tool.py", line 54, in csv_files
  File "pandas\io\parsers\readers.py", line 912, in read_csv
  File "pandas\io\parsers\readers.py", line 577, in _read
  File "pandas\io\parsers\readers.py", line 1407, in __init__
  File "pandas\io\parsers\readers.py", line 1661, in _make_engine
  File "pandas\io\common.py", line 859, in get_handle
FileNotFoundError: [Errno 2] No such file or directory: 'E:\\python\\jee_counsellor\\output\\csab\\2022\\round_2\\ranks.csv'
[19596] Failed to execute script 'tool' due to unhandled exception!

我的代码片段失败的地方。

        cwd = os.getcwd()
        csab_rounds = round
        csv_path = os.path.join(cwd, "csab", "2022", f"round_{csab_rounds}", "ranks.csv")
        df = pd.read_csv(csv_path)

我是否需要使用 pyinstaller 更新我的代码或任何其他解决方法?

python python-3.x windows pyinstaller executable
© www.soinside.com 2019 - 2024. All rights reserved.