I'm new to python and I don't know much yet. So, I wanted to convert my python project to an exe file, and so I followed the steps like in every youtube tutorial, terminal, pyinstaller and stuff (I use Pychram), but soon I realized that the icon I set for my exe isn't loading unless it's in the same folder as dist and .spec file. I decided to search some, I found a way on this site: https://clay-atlas.com/us/blog/2020/11/04/python-en-package-pyinstaller-picture/ (3rd method), but i was unable to decode it, I just need to replace something with my filename but I don't understand where exactly, like is pic2str a variable or a project name? Thanks. (Code might be slightly shifted in here copy from the website if you need)
import base64
def pic2str(file, functionName):
pic = open(file, 'rb')
content = '{} = {}\n'.format(functionName, base64.b64encode(pic.read()))
pic.close()
with open('pic2str.py', 'a') as f:
f.write(content)
if __name__ == '__main__':
pic2str('test.png', 'explode')
And this:
import sys
import base64
from io import BytesIO
from PyQt5 import QtWidgets
from PyQt5.QtGui import *
from test import Ui_MainWindow
from PIL import Image, ImageQt
from pic2str import explode
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
# Load byte data
byte_data = base64.b64decode(explode)
image_data = BytesIO(byte_data)
image = Image.open(image_data)
# PIL to QPixmap
qImage = ImageQt.ImageQt(image)
image = QPixmap.fromImage(qImage)
# QPixmap to QLabel
self.ui.label.setPixmap(image)
self.ui.label.setScaledContents(True)
if __name__ == '__main__':
app = QtWidgets.QApplication([])
window = MainWindow()
window.show()
sys.exit(app.exec_())