[GH-ISSUE #121] Not able to get images in exe generated from python code. #115

Closed
opened 2026-02-26 12:20:32 +03:00 by kerem · 13 comments
Owner

Originally created by @mchaudh4 on GitHub (Sep 1, 2020).
Original GitHub issue: https://github.com/brentvollebregt/auto-py-to-exe/issues/121

I am stuck with an unusual problem. I have a GUI code written in Python PyQt5. It has images, put inside an image folder and many python files. This GUI is working fine in Pycharm. I am able to generate a standalone executable file for this project using auto-py-to-exe. When i the run the exe, i am able to see buttons, lineedits, but no images are visible in GUI. I have really tried hard and searched a lot of internet, but still could not understand the concept of getting the images. The auto-py-to-exe application looks as shown.Please give me the solution of this problem.

Originally created by @mchaudh4 on GitHub (Sep 1, 2020). Original GitHub issue: https://github.com/brentvollebregt/auto-py-to-exe/issues/121 I am stuck with an unusual problem. I have a GUI code written in Python PyQt5. It has images, put inside an image folder and many python files. This GUI is working fine in Pycharm. I am able to generate a standalone executable file for this project using auto-py-to-exe. When i the run the exe, i am able to see buttons, lineedits, but no images are visible in GUI. I have really tried hard and searched a lot of internet, but still could not understand the concept of getting the images. The auto-py-to-exe application looks as shown.Please give me the solution of this problem.
kerem closed this issue 2026-02-26 12:20:32 +03:00
Author
Owner

@brentvollebregt commented on GitHub (Sep 1, 2020):

I am going to assume you have read the linked post "Issues When Using auto-py-to-exe". After using one directory mode, were the images that you added in the additional files section where you expected them to be?

<!-- gh-comment-id:684677841 --> @brentvollebregt commented on GitHub (Sep 1, 2020): I am going to assume you have read the linked post "Issues When Using auto-py-to-exe". After using one directory mode, were the images that you added in the additional files section where you expected them to be?
Author
Owner

@mchaudh4 commented on GitHub (Sep 1, 2020):

I read the "Issues when using auto-py-to-exe later. I will test the exe tomorrow after going to office tomorrow. Please make a video regarding all the possible scenario. Your software is GREAT.

<!-- gh-comment-id:684870644 --> @mchaudh4 commented on GitHub (Sep 1, 2020): I read the "Issues when using auto-py-to-exe later. I will test the exe tomorrow after going to office tomorrow. Please make a video regarding all the possible scenario. Your software is GREAT.
Author
Owner

@brentvollebregt commented on GitHub (Sep 1, 2020):

No, I will not make a video for your specific situation. That post is linked in the readme, in the description of the video associated with this tool and is linked twice in the UI. I expect that you have tried to do some of your own research before you ask me what's wrong.

<!-- gh-comment-id:685095575 --> @brentvollebregt commented on GitHub (Sep 1, 2020): No, I will not make a video for your specific situation. That post is linked in the readme, in the description of the video associated with this tool and is linked twice in the UI. I expect that you have tried to do some of your own research before you ask me what's wrong.
Author
Owner

@mchaudh4 commented on GitHub (Sep 2, 2020):

Hi , i read all the documents. The executable is generated. But, I am getting the error:
image
Do you have any idea, why i am getting this error, failed to execute script.

<!-- gh-comment-id:685785211 --> @mchaudh4 commented on GitHub (Sep 2, 2020): Hi , i read all the documents. The executable is generated. But, I am getting the error: ![image](https://user-images.githubusercontent.com/36970109/91998436-305b4d80-ed09-11ea-8409-fd9df72736b4.png) Do you have any idea, why i am getting this error, failed to execute script.
Author
Owner

@mchaudh4 commented on GitHub (Sep 2, 2020):

I resolved the issue. The software did not included the python-can library, which was essential for my software to work. How will the user know, which library the software will include, and which libraries you have to add it yourself?
Also, when i tried to generate a single file executable, the images are not included.

<!-- gh-comment-id:685861954 --> @mchaudh4 commented on GitHub (Sep 2, 2020): I resolved the issue. The software did not included the python-can library, which was essential for my software to work. How will the user know, which library the software will include, and which libraries you have to add it yourself? Also, when i tried to generate a single file executable, the images are not included.
Author
Owner

@brentvollebregt commented on GitHub (Sep 3, 2020):

Using the debugging instructions would have helped you identify the issue quite quickly.

You will know which libraries will be included automatically and which need to be added manually by running the application and looking at the output for any errors.

Are you 100% sure your images are not included? Or are you referencing them incorrectly? Did you read the help post I have provided - it discusses this issue in great depth.

<!-- gh-comment-id:686267641 --> @brentvollebregt commented on GitHub (Sep 3, 2020): Using the [debugging instructions](https://nitratine.net/blog/post/issues-when-using-auto-py-to-exe/#debugging) would have helped you identify the issue quite quickly. You will know which libraries will be included automatically and which need to be added manually by running the application and looking at the output for any errors. Are you 100% sure your images are not included? Or are you referencing them incorrectly? Did you read the help post I have provided - it [discusses this issue](https://nitratine.net/blog/post/issues-when-using-auto-py-to-exe/#the-difference-between-one-directory-and-one-file) in great depth.
Author
Owner

@mchaudh4 commented on GitHub (Sep 5, 2020):

The images were not included when i generated the single file executable. The images were included when i generated the folder kind of executable.
Also, there was no error i could observe related to python- can library in the executable. I debugged the error by matching the the libraries in executable generated and the imported libraries used in the code.

<!-- gh-comment-id:687522402 --> @mchaudh4 commented on GitHub (Sep 5, 2020): The images were not included when i generated the single file executable. The images were included when i generated the folder kind of executable. Also, there was no error i could observe related to python- can library in the executable. I debugged the error by matching the the libraries in executable generated and the imported libraries used in the code.
Author
Owner

@brentvollebregt commented on GitHub (Sep 5, 2020):

How are you sure that the images have not been included? What steps have you performed to validate this?

<!-- gh-comment-id:687559334 --> @brentvollebregt commented on GitHub (Sep 5, 2020): How are you sure that the images have not been included? What steps have you performed to validate this?
Author
Owner

@mchaudh4 commented on GitHub (Sep 5, 2020):

I tested it thoroughly. When i tried generated a single file executable,
the images were not visible when the GUI runs. When i tried generating a
folder kind of executable, the images are visible.

On Sat, Sep 5, 2020 at 2:19 AM Brent Vollebregt notifications@github.com
wrote:

How are you sure that the images have not been included? What steps have
you performed to validate this?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/brentvollebregt/auto-py-to-exe/issues/121#issuecomment-687559334,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AI2B47MWU345J4XPTA57CQLSEHJ57ANCNFSM4QRI35IA
.

<!-- gh-comment-id:687610764 --> @mchaudh4 commented on GitHub (Sep 5, 2020): I tested it thoroughly. When i tried generated a single file executable, the images were not visible when the GUI runs. When i tried generating a folder kind of executable, the images are visible. On Sat, Sep 5, 2020 at 2:19 AM Brent Vollebregt <notifications@github.com> wrote: > How are you sure that the images have not been included? What steps have > you performed to validate this? > > — > You are receiving this because you authored the thread. > Reply to this email directly, view it on GitHub > <https://github.com/brentvollebregt/auto-py-to-exe/issues/121#issuecomment-687559334>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AI2B47MWU345J4XPTA57CQLSEHJ57ANCNFSM4QRI35IA> > . >
Author
Owner

@brentvollebregt commented on GitHub (Sep 5, 2020):

Regarding you're keeping all the parameters in the tool the same, I do not see why they wouldn't be there.

Are you using the "The one-file Resource Wrapper" snippet that I provided? You haven't said anything about it? I believe those files are there but you're not looking for them in the right place. Simply running the exe and the images not appearing in the GUI is not enough proof to tell me they're not there.

What was your thorough testing?

In the help post I extensively link I state:

One file mode is a bit different, instead of putting all the files in a folder, it puts them in something like a zip file which is contained in the end executable. When you run the executable, the files contained internally are unpacked to a new temporary directory.

Also due to the files being unpacked to a new temporary directory on execution, the files that you modified added that were in the same directory as the executable will not be there on the next run because they are now in a different unknown folder.

The reason you need to use this extra bit of code is because a one-file exe will unpack all of it's contents to a new folder in the operating systems temporary directory. This means the current working directory initially set in the application will not be where the files have been unpacked to unlike one-directory. This is why using relative references will work in one-directory but not in one-file - you need to adjust for the fact that the root of the project is now somewhere different.

Lets do some checking where we actually look at the folder:

  1. Create this script:
import sys, os

def resource_path(relative_path):  # Snippet from the post you have read
    """ Get the absolute path to the resource, works for dev and for PyInstaller """
    try:
        # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
    except Exception:
        base_path = os.path.abspath(".")

    return os.path.join(base_path, relative_path)

print('Path:', resource_path('.'))  # Print out the root path of the bundle
input()  # Wait for enter to be pressed - we need this so the one-file directory is not deleted until we stop the script
  1. Add all your image files in auto-py-to-exe and bundle the above script as one-directory and console-based.
  2. Run the output exe and it should print out a path, go to that path in your file explorer - your files should be somewhere in that folder or a sub-folder.
  3. Go back to the console window and press enter to end the script.
  4. Go back to auto-py-to-exe and add all your image files and bundle the above script again as one-file and console-based.
  5. Run the output exe and it should print out a path, go to that path in your file explorer - your files should be somewhere in that folder or a sub-folder.
  6. After you have looked at that folder, you can then go back to the console window and press enter to end the script.

Step 6 should prove that your images are coming through. Just because we are bundling a different script doesn't mean that this will change which files are output (aside from Python script).

<!-- gh-comment-id:687667654 --> @brentvollebregt commented on GitHub (Sep 5, 2020): Regarding you're keeping all the parameters in the tool the same, I do not see why they wouldn't be there. Are you using the "The one-file Resource Wrapper" snippet that I provided? You haven't said anything about it? I believe those files are there but you're not looking for them in the right place. Simply running the exe and the images not appearing in the GUI is not enough proof to tell me they're not there. What was your thorough testing? In the help post I extensively link I state: > One file mode is a bit different, instead of putting all the files in a folder, it puts them in something like a zip file which is contained in the end executable. When you run the executable, the files contained internally are unpacked to a new temporary directory. > Also due to the files being unpacked to a new temporary directory on execution, the files that you modified added that were in the same directory as the executable will not be there on the next run because they are now in a different unknown folder. > The reason you need to use this extra bit of code is because a one-file exe will unpack all of it's contents to a new folder in the operating systems temporary directory. This means the current working directory initially set in the application will not be where the files have been unpacked to unlike one-directory. This is why using relative references will work in one-directory but not in one-file - you need to adjust for the fact that the root of the project is now somewhere different. Lets do some checking where we actually look at the folder: 1. Create this script: ```python import sys, os def resource_path(relative_path): # Snippet from the post you have read """ Get the absolute path to the resource, works for dev and for PyInstaller """ try: # PyInstaller creates a temp folder and stores path in _MEIPASS base_path = sys._MEIPASS except Exception: base_path = os.path.abspath(".") return os.path.join(base_path, relative_path) print('Path:', resource_path('.')) # Print out the root path of the bundle input() # Wait for enter to be pressed - we need this so the one-file directory is not deleted until we stop the script ``` 2. Add all your image files in auto-py-to-exe and bundle the above script as **one-directory** and **console-based**. 3. Run the output exe and it should print out a path, go to that path in your file explorer - your files should be somewhere in that folder or a sub-folder. 4. Go back to the console window and press enter to end the script. 5. Go back to auto-py-to-exe and add all your image files and bundle the above script again as **one-file** and **console-based**. 6. Run the output exe and it should print out a path, go to that path in your file explorer - your files should be somewhere in that folder or a sub-folder. 7. After you have looked at that folder, you can then go back to the console window and press enter to end the script. Step 6 should prove that your images are coming through. Just because we are bundling a different script doesn't mean that this will change which files are output (aside from Python script).
Author
Owner

@brentvollebregt commented on GitHub (Dec 24, 2020):

There has been no response by @mchaudh4 in more than three months so I'm going to assume this was resolved.

<!-- gh-comment-id:750725132 --> @brentvollebregt commented on GitHub (Dec 24, 2020): There has been no response by @mchaudh4 in more than three months so I'm going to assume this was resolved.
Author
Owner

@Akashmsagar0707 commented on GitHub (Dec 24, 2023):

The images were not included when i generated the single file executable. The images were included when i generated the folder kind of executable. Also, there was no error i could observe related to python- can library in the executable. I debugged the error by matching the the libraries in executable generated and the imported libraries used in the code.

I am stuck with this issue please help me

<!-- gh-comment-id:1868576448 --> @Akashmsagar0707 commented on GitHub (Dec 24, 2023): > The images were not included when i generated the single file executable. The images were included when i generated the folder kind of executable. Also, there was no error i could observe related to python- can library in the executable. I debugged the error by matching the the libraries in executable generated and the imported libraries used in the code. I am stuck with this issue please help me
Author
Owner

@brentvollebregt commented on GitHub (Dec 24, 2023):

@Akashmsagar0707 please create a new issue and fill out the complete issue template - make sure to include a minimal reproducible example.

<!-- gh-comment-id:1868577888 --> @brentvollebregt commented on GitHub (Dec 24, 2023): @Akashmsagar0707 please create a new issue and fill out the complete issue template - make sure to include a minimal reproducible example.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/auto-py-to-exe#115
No description provided.