【问题标题】:Where does a file gets stored that came with a .exe file on Windows 10/11?Windows 10/11 上的 .exe 文件随附的文件存储在哪里?
【发布时间】:2021-12-16 18:59:36
【问题描述】:

所以我用 Nuitka 将我想要编译的这个 python 文件(它称为 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 存储在哪里?

【问题讨论】:

    标签: python exe nuitka


    【解决方案1】:

    通过查看Nuitka documentation,它说:

    # Create a binary that unpacks into a temporary folder
    python -m nuitka --onefile program.py
    

    注意

    还有更多特定于平台的选项,例如与图标有关, 启动屏幕和版本信息,请考虑 --help 输出 有关这些的详细信息,请查看“美观”部分。

    同样,在 Windows 上,对于临时文件目录,默认情况下 使用了用户一,但是这可以用路径覆盖 规范中给出 --windows-onefile-tempdir-spec=%TEMP%\\onefile_%PID%_%TIME% 这是 默认并断言创建的临时目录不能 碰撞。

    所以,我认为输出应该显示为%TEMP% 中描述的子目录,应该是路径C:\Users\%USERNAME%\AppData\Local\Temp\

    如果你想使用默认路径,你必须在 Python 中的 %TEMP% 中找到动态命名的子文件夹 (onefile_%PID%_%TIME%),然后你可以 get the current process ID,然后使用模糊模式或其他东西,因为您将无法知道确切的时间。否则,设置自定义路径。

    【讨论】:

    • 那么PDF文件应该在TEMP文件中?
    • @Coder 它应该在 Temp 文件夹中动态命名的 子文件夹 中。他们这样做是为了如果您多次运行它,它不会覆盖文件。如果您将路径更改为 %TEMP%\\onefile 之类的内容(没有 PID 和 TIME 变量),那么每次运行程序时,文件都会被覆盖,或者如果您运行多个进程,文件可能会被锁定。
    • 我用你建议的论点得到了它!非常感谢!
    猜你喜欢
    • 2018-02-03
    • 1970-01-01
    • 1970-01-01
    • 2010-11-15
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-04
    相关资源
    最近更新 更多