[GH-ISSUE #484] symbols-images into pushbutton auto-py-to-exe #380

Closed
opened 2026-02-26 12:21:25 +03:00 by kerem · 5 comments
Owner

Originally created by @shlomiz89 on GitHub (May 16, 2024).
Original GitHub issue: https://github.com/brentvollebregt/auto-py-to-exe/issues/484

          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).

Originally posted by @brentvollebregt in https://github.com/brentvollebregt/auto-py-to-exe/issues/121#issuecomment-687667654

Hi, i have the same problem.
i did the steps you mentioned above, the exe file not showing my images. but the images exist in the directory ("one directory" option)
if i run through Spyder it's work good

the python code written as following:

    self.enterPB = QtWidgets.QPushButton(self.centralwidget)
    self.enterPB.setGeometry(QtCore.QRect(50, 370, 61, 51))
    self.enterPB.setStyleSheet("")
    self.enterPB.setText("")
    icon = QtGui.QIcon()
    icon.addPixmap(QtGui.QPixmap("enter.jpg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
    self.enterPB.setIcon(icon)
    self.enterPB.setIconSize(QtCore.QSize(61, 51))
    self.enterPB.setObjectName("enterPB")

python file
exe file

Originally created by @shlomiz89 on GitHub (May 16, 2024). Original GitHub issue: https://github.com/brentvollebregt/auto-py-to-exe/issues/484 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). _Originally posted by @brentvollebregt in https://github.com/brentvollebregt/auto-py-to-exe/issues/121#issuecomment-687667654_ Hi, i have the same problem. i did the steps you mentioned above, the exe file not showing my images. but the images exist in the directory ("one directory" option) if i run through Spyder it's work good the python code written as following: self.enterPB = QtWidgets.QPushButton(self.centralwidget) self.enterPB.setGeometry(QtCore.QRect(50, 370, 61, 51)) self.enterPB.setStyleSheet("") self.enterPB.setText("") icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap("enter.jpg"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.enterPB.setIcon(icon) self.enterPB.setIconSize(QtCore.QSize(61, 51)) self.enterPB.setObjectName("enterPB") ![python file](https://user-images.githubusercontent.com/70206271/331166888-c56e3cf4-ce8d-4444-b00a-1cbfa9a01e21.PNG) ![exe file](https://user-images.githubusercontent.com/70206271/331166916-df856de0-f757-4055-af50-49b0a2fa1bdb.PNG)
kerem 2026-02-26 12:21:25 +03:00
  • closed this issue
  • added the
    not-a-bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (May 16, 2024):

👋 Hi, just a reminder that if you haven't read the help post yet, give it a read to see if your issue is covered in it and make sure to follow the debugging section.

Also please note, as stated in the README, if your issue is only associated with your application and not auto-py-to-exe itself, please do not create an issue in this repository - instead, comment on the help post, video or create a new discussion.

<!-- gh-comment-id:2114854269 --> @github-actions[bot] commented on GitHub (May 16, 2024): 👋 Hi, just a reminder that if you haven't read [the help post](https://nitratine.net/blog/post/issues-when-using-auto-py-to-exe/) yet, give it a read to see if your issue is covered in it and make sure to follow [the debugging section](https://nitratine.net/blog/post/issues-when-using-auto-py-to-exe/#debugging). Also please note, as stated in the README, if your issue is only associated with your application and not auto-py-to-exe itself, please do not create an issue in this repository - instead, comment on the help [post](https://nitratine.net/blog/post/issues-when-using-auto-py-to-exe/), [video](https://youtu.be/OZSZHmWSOeM) or create a [new discussion](https://github.com/brentvollebregt/auto-py-to-exe/discussions).
Author
Owner

@brentvollebregt commented on GitHub (May 16, 2024):

I see you are referencing "enter.jpg" in your script - since this is a relative reference, it will resolve relatively to the current working directory, which will most likely not be where the file is actually being stored in the bundle output.

To fix this, you need to wrap file references with resource_path to correctly turn a relative path into an absolute path which will point to the correct file. For example,

icon.addPixmap(QtGui.QPixmap(resource_path("enter.jpg")), QtGui.QIcon.Normal, QtGui.QIcon.Off)

You can read more about this in the help post under "The one-file Resource Wrapper".

<!-- gh-comment-id:2114882023 --> @brentvollebregt commented on GitHub (May 16, 2024): I see you are referencing `"enter.jpg"` in your script - since this is a relative reference, it will resolve relatively to the current working directory, which will most likely not be where the file is actually being stored in the bundle output. To fix this, you need to wrap file references with `resource_path` to correctly turn a relative path into an absolute path which will point to the correct file. For example, ```py icon.addPixmap(QtGui.QPixmap(resource_path("enter.jpg")), QtGui.QIcon.Normal, QtGui.QIcon.Off) ``` You can read more about this in the help post under ["The one-file Resource Wrapper"](https://nitratine.net/blog/post/issues-when-using-auto-py-to-exe/#the-one-file-resource-wrapper).
Author
Owner

@shlomiz89 commented on GitHub (May 16, 2024):

Thank you very much for fast answer

should i write this code into my code?

i mentioned this in the class before setupUi def

def resource_path(relative_path):
    import sys, os
    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)

and reference it in
icon.addPixmap(QtGui.QPixmap(resource_path("enter.jpg")), QtGui.QIcon.Normal, QtGui.QIcon.Off)

i receive an error - undefined name "resource_path"

<!-- gh-comment-id:2115147677 --> @shlomiz89 commented on GitHub (May 16, 2024): Thank you very much for fast answer should i write this code into my code? i mentioned this in the class before setupUi def def resource_path(relative_path): import sys, os 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) and reference it in icon.addPixmap(QtGui.QPixmap(resource_path("enter.jpg")), QtGui.QIcon.Normal, QtGui.QIcon.Off) i receive an error - undefined name "resource_path"
Author
Owner

@brentvollebregt commented on GitHub (May 16, 2024):

Yes, you need to add that function yourself. Nothing provides it for you and this tool doesn't add anything to your application.

<!-- gh-comment-id:2115152398 --> @brentvollebregt commented on GitHub (May 16, 2024): Yes, you need to add that function yourself. Nothing provides it for you and this tool doesn't add anything to your application.
Author
Owner

@shlomiz89 commented on GitHub (May 16, 2024):

you the besttttt!!!!!!!
thank you <3

<!-- gh-comment-id:2115181142 --> @shlomiz89 commented on GitHub (May 16, 2024): you the besttttt!!!!!!! thank you <3
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#380
No description provided.