Answer the question
In order to leave comments, you need to log in
How to solve the following problem with creating exe file from ru and ui files?
Hello,
such a task: there is one start.py file that decides which of the two .py files to open next; these two main_gui.ru and main_gui2.py files are almost identical, the main difference is that they are linked to different .ui files (GUIs are opened in different languages), and they are also linked to several more auxiliary .py files.
How can I make this .exe file work? (I've tried many things). And why, if I use os.system('python main_gui(2).py') to open it - everything works fine before creating the .exe, but when I use import main_gui(2) - it seems to import everything, but the corresponding interface does not open?
Thanks in advance
Answer the question
In order to leave comments, you need to log in
When creating an exe file, this path:
is not good at all, it will only run on a computer with python installed.
what about:
if you use pyinstaller to create an exe with the -F flag to create a single exe file with the contents packed into it, then to add other data such as ui files, you need to add them to the pyinstaller options. The --add-data parameter is used, and consists of two values, the name of the added file and the path to it, separated by the ";" sign. For example, if the file is called gui1.ui and is located in the same directory next to the script, then the pyinstaller parameters will be look something like this:
pyinstaller -F --add-data gui1.ui;. start.py
The dot means the current directory.
UPDATE
You need to add the following code to the file that loads the data ui files:
import os
import sys
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
if getattr(sys, 'frozen', False):
base_path = sys._MEIPASS
else:
base_path = os.getcwd()
return os.path.join(base_path, relative_path)
main_window = uic.loadUiType(resource_path('gui.ui')))[0]
class Window(QMainWindow, main_window):
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question