使用pyinstaller将.py转换为.exe时需要数据文件吗?

问题描述

(第一次)。 所以我试图在我的代码中使用2个excel文件一个用于获取数据集,另一个用于存储数据,我试图用pyinstaller制作一个exe文件,但我认为我应该将这2个文件放在某个地方或对它们进行处理,但是由于对编码非常陌生,我真的有0条线索。

使用了--add-data数据集.xlsx;。并收到此错误[截图] [1]: 开始? y / n ÿ 追溯(最近一次呼叫过去): 文件“ neo.py,第4行,在 文件“”,第1行,在 NameError:名称“ y”未定义 [1808]无法执行脚本neo [1]:https://i.stack.imgur.com/g8wsn.png

我认为这条线有问题:

    start = input("Start? y/n \n")                                              
    while True:
     if start in ["y","yes","Yes","YES","Y"]:
      print("Starting")
      break
    elif start in ["n","no","NO","No","N"]:
     print("Have a nice day!")
     exit()
     break
    else:
     print("Invalid answer,try again")
     exit()
     break

(很抱歉,我太草率了,我很新:D)

解决方法

是的

根据您的comment,您需要这些文件之一。您可以使用#include <vector> #include <functional> using FunctionCall = std::function< void(int,int) >; using FunctionCallList = std::vector<FunctionCall>; void checkExecutionOrder(FunctionCallList call_list){ for (auto f : call_list) { f(42,42); } } void foo(int x,int y){} int main() { checkExecutionOrder( { foo,foo } ); } 选项将其添加到exe。有关更多信息,请参见PyInstaller文档。

,

您可以在运行exe时直接选择那些文件。我用它从任何位置导入Excel数据:

import pandas as pd
import easygui

def ExcelData():
    data = pd.ExcelFile(easygui.fileopenbox("Please select the Excel file with data to be uploaded:","Data"))
    sheetlist = data.sheet_names
    sheet = easygui.choicebox("Select a Sheet to be Extracted:","Data",sheetlist)
    output = data.parse(sheet_name=sheet)
    return(output)
,

使用--add-data file.xlsx作为我的朋友在这里建议,然后我检查了一下,因为我将python添加到路径中,但是没有激活它,所以我去了并用

激活了它
     c:\Anaconda3\Scripts\activate base

cmd,而不是使用的pyinstaller。 ofc它不在此目录中,但您可以获取摘要