所以我制作了这个 python 文件,我想用 Nuitka 将其编译(称为 ElPatron)为 .exe 文件。 我做得正确,这是随之而来的 dist 文件夹(使用 Nuitka 的 --standalone 参数)
这是我使用的 nuitka 命令:
.\python.exe -m nuitka --mingw64 .\ElPatron.py --standalone --onefile --windows-disable-console --windows-icon-from-ico=pdf.ico --include-data-file=C:\Users\User\AppData\Local\Programs\Python\Python39\example.pdf=example.pdf
我使用 Nuitka 的 --include-data-file 参数将 pdf 包含在 exe 中
我现在遇到的问题是,我不知道执行 ElPatron.exe 时这个(example.pdf)存储在哪里。我想知道这一点,以便我可以在我的 Python 项目中调用它。
问题
当 Windows 计算机执行 .exe(包含 pdf)时,example.pdf 存储在哪里?
最佳答案
查看Nuitka documentation ,它说:
# Create a binary that unpacks into a temporary folder python -m nuitka --onefile program.py
Note
There are more platform specific options, e.g. related to icons, splash screen, and version information, consider the
--help
output for the details of these and check the section “Good Looks”.Again, on Windows, for the temporary file directory, by default the user one is used, however this is overridable with a path specification given in
--windows-onefile-tempdir-spec=%TEMP%\\onefile_%PID%_%TIME%
which is the default and asserts that the temporary directories created cannot collide.
因此,我认为输出应按所述显示为 %TEMP%
中的子目录,该路径应为路径 C:\Users\%USERNAME%\AppData\Local\温度\
.
如果您想使用默认路径,则必须在 中找到动态命名的子文件夹 (
在 Python 中,您可以 get the current process ID ,然后使用模糊模式或其他东西,因为您将无法知道确切的时间。否则,设置自定义路径。onefile_%PID%_%TIME%
) >%TEMP%
关于python - Windows 10/11 上的 .exe 文件附带的文件存储在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70384301/