编译引用 xlsx 文件的 python 文件而不编译 xslx 文件

Compile python file that references to xlsx files without compiling the xslx files

我正在尝试编译我的 py 文件,但最终出现错误。 脚本从 2 excel 个文件中读取并写回 1 编译 py 文件时出现错误 FileNotFoundError: [Errno 2] No such file or directory: 'file.xlsx'。虽然文件在那里并且可以在我执行 py 文件时找到,但我似乎无法解决这个问题。 当我将路径从 relative 更改为 full 时,会弹出此错误

workbook = load_workbook(filename="C:\Users\userxdx\Desktop\Excellsupport\file.xlsx")
                                  ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

为了编译,我使用了 py2exe(对于 windows) 我在这里错过了什么?

这不起作用,因为 \escape character。例如,“\n”将在字符串中创建一个新行。要忽略 escape characters,请在字符串的开头放置一个 r,如下所示:

filename=r"C:\Users\userxdx\Desktop\Excellsupport\file.xlsx"