![]() ![]() windowed: Ensures that no console is opened during execution. onefile: Creates a one-file bundled executable. Now run the following code (replace the image names and the file name): pyinstaller -onefile -windowed -add-data "picture1.jpeg." -add-data "picture2.png." your_file.py Image1 = Image.open(resource_path("image.png")) Replace the file names with resource_path("FILENAME").Įxample: image1 = Image.open("image.png") Make sure the images you need for your program are also in the folder with your Python file you want to make executable.Īdd the following to the Python file you want to make executable: import os Here is my solution that works for Mac OS at least (I will post a solution for Windows later):Ĭhange to the directory with the file to be made executable: cd PATH_OF_YOUR_FILE Return os.path.join(base_path, relative_path)ĭespite the explanations on the Internet, it took me several hours to come up with an independent application that contains several images, does not open a console while execution and is combined in only one file. # PyInstaller creates a temp folder and stores path in _MEIPASS ![]() """ Get absolute path to resource, works for dev and for PyInstaller """ # -*- mode: python -*-Ī.datas += Ĭonsole=True, icon='C:\\Users\\elu\\PycharmProjects\\Prosjektet\\Forsok splitting\\AMOS.ico')Īnd adding the following to my main.py script def resource_path(relative_path): I belive I found the solution to my problem. ![]() My spec file looks the following: # -*- mode: python -*. ![]() I think the solution may be in this link, but I haven't understood it.īundling data files with PyInstaller (-onefile) Pyinstaller does not show images and iconīut then again the whole point of -onefile is to have exactly that, not need the image in addition. One solution is to include the image in the folder of the exe as seen in the link below: In the program, I include an image in my plots, and when I run the program alone in its folder, I get the following: IOError: No such file or directory: 'Logo.png' pyinstaller.exe -onefile -icon='Loco.ico program.py I have created an exe file using Pyinstaller. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |