[英]Where does a file gets stored that came with a .exe file on Windows 10/11?
So I have made this python file which I want to compile (it's called ElPatron) to a.exe file with Nuitka.所以我制作了这个 python 文件,我想用 Nuitka 将它编译(称为 ElPatron)为 a.exe 文件。 I did it correctly and this is the dist folder that came with that (using the --standalone argument that Nuitka has)
我做得对,这是附带的 dist 文件夹(使用 Nuitka 的 --standalone 参数)
This is the nuitka command I used:这是我使用的 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
I included the pdf in the exe using the --include-data-file argument from Nuitka我使用 Nuitka 的 --include-data-file 参数在 exe 中包含了 pdf
The problem I have now is that I don't know where this(the example.pdf) get's stored when the ElPatron.exe is executed.我现在遇到的问题是,当执行 ElPatron.exe 时,我不知道这个(example.pdf)存储在哪里。 I want to know this so I can call it inside my Python project.
我想知道这个,所以我可以在我的 Python 项目中调用它。
The question问题
Where does the example.pdf get stored when a windows computer executes the.exe (containing the pdf)?当 windows 计算机执行 .exe(包含 pdf)时,example.pdf 存储在哪里?
From looking at the Nuitka documentation , it says:通过查看Nuitka 文档,它说:
# Create a binary that unpacks into a temporary folder python -m nuitka --onefile program.py
Note
笔记
There are more platform specific options, eg related to icons, splash screen, and version information, consider the
--help
output for the details of these and check the section “Good Looks”.还有更多特定于平台的选项,例如与图标、启动屏幕和版本信息相关的选项,请考虑
--help
output 了解这些详细信息并查看“美观”部分。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.同样,在 Windows 上,对于临时文件目录,默认情况下使用用户一,但是可以使用
--windows-onefile-tempdir-spec=%TEMP%\\onefile_%PID%_%TIME%
中给出的路径规范覆盖--windows-onefile-tempdir-spec=%TEMP%\\onefile_%PID%_%TIME%
是默认值,它断言创建的临时目录不会发生冲突。
So, I think the output should show up as a subdirectory in %TEMP%
as described, which should be the path C:\Users\%USERNAME%\AppData\Local\Temp\
.所以,我认为 output 应该显示为
%TEMP%
中的子目录,如所述,它应该是路径C:\Users\%USERNAME%\AppData\Local\Temp\
。
If you want to use the default path, you'll have to find the dynamically-named subfolder ( onefile_%PID%_%TIME%
) within %TEMP%
in Python, and you can get the current process ID , then use a fuzzy pattern or something, as you won't be able to know the exact time.如果要使用默认路径,则必须在 Python 中的
%TEMP%
内找到动态命名的子文件夹( onefile_%PID%_%TIME%
),并且可以获取当前进程 ID ,然后使用模糊模式或其他东西,因为您将无法知道确切的时间。 Otherwise, set a custom path.否则,设置自定义路径。
A janky way of doing this might be:这样做的一个笨拙的方法可能是:
def resource_path(self,relative_path):
""" Get absolute path to resource, works for python file and compiled exe """
if not sys.argv[0].endswith('exe'): return os.path.join(os.path.dirname(sys.argv[0]),relative_path)
else:
if not hasattr(self,'respth'):
temp_appd=os.path.join(os.getenv('localappdata'),'Temp')
resdict={}
for item in os.listdir(temp_appd):
if len(re.findall('''onefile_\d+_\d+''',item))>0:
resdict[re.findall('''onefile_\d+_(\d+)''',item)[0]]=item
self.respth=resdict[max(list(resdict.keys()))]
logging.info('path set to '+os.path.join(os.getenv('localappdata'),'Temp',self.respth,relative_path))
return os.path.join(os.getenv('localappdata'),'Temp',self.respth,relative_path)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.