简体   繁体   English

pyinstaller build生成可执行文件后添加文件的位置

[英]Location of the added files after the executable file is generated by pyinstaller build

I built an executable file for my python application using pyinstaller. 我使用pyinstaller为python应用程序构建了一个可执行文件。 I added two folders (data and audio samples) by using --add-data command. 我使用--add-data命令添加了两个文件夹(数据和音频样本)。 The executable is working. 可执行文件正在运行。 But where can I find the two data folders I added. 但是在哪里可以找到我添加的两个数据文件夹。 Aren't they put into the dist folder with executable file? 他们不是将可执行文件放入dist文件夹吗?

When you add a data to PyInstaller it would bring your data and extract it in one-file mode in temp folder (eg on Windows it would be something like C:\\Users\\<User>\\Appdata\\local\\temp\\_MEI60482\\ ) so you need to change your code to open your files from that directory. 当您将数据添加到PyInstaller时,它将带入您的数据并将其以one-file模式提取到temp文件夹中(例如,在Windows上,它将类似于C:\\Users\\<User>\\Appdata\\local\\temp\\_MEI60482\\ )因此,您需要更改代码才能从该目录打开文件。 A good practice is to use this function in your code to retrieve your data. 一个好的做法是在代码中使用此功能来检索数据。 When running executable sys._MEIPASS would be equal to the PyInstaller temp folder. 运行可执行文件sys._MEIPASS将等于PyInstaller临时文件夹。

def resource_path(relative_path):
    if hasattr(sys, '_MEIPASS'):
        return os.path.join(sys._MEIPASS, relative_path)
    return os.path.join(os.path.abspath("."), relative_path)

Then you can use it with something like source = resource_path("audio.zip") . 然后,您可以将其与source = resource_path("audio.zip")类的东西一起使用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 pyinstaller 将多个 .py 文件构建为单个可执行文件? - How to build multiple .py files into a single executable file using pyinstaller? pyInstaller 仅构建可执行文件 - pyInstaller build executable only 如何抑制pyinstaller生成的可执行文件窗口中的所有警告 - How to suppress all warnings in window of executable file generated by pyinstaller 减少Pyinstaller生成的可执行文件的文件大小的一些常规技巧 - What are some general tips to reduce the file size for a Pyinstaller generated executable Pyinstaller 可执行文件未运行 - Pyinstaller Executable File Not Running 当我尝试使用 pyinstaller 构建可执行文件时,只创建了 a.spec 文件,如何使用 pyinstaller 构建可执行文件 - When i try to build an executable file with pyinstaller only a .spec file is created, How do i build an executable with pyinstaller 如何在可执行文件中使用 pyinstaller 包含特定的 .jar 文件? - How to include specific .jar files with pyinstaller in executable file? pyinstaller:当我用pyinstaller制作.exe文件时,在python中使用内置函数打开的可执行文件关闭1秒 - Pyinstaller: Executable file opened with built in function in python closes after 1 sec when i make .exe file with pyinstaller 自动更新使用pyinstaller生成的python可执行文件 - Auto updating a python executable generated with pyinstaller Python 3.5使用pyinstaller生成的可执行文件创建.rpm - Python 3.5 create .rpm with pyinstaller generated executable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM