[英]How do I create an exe file of gui made using pyqt5?(There are several ui files)
I tried to create an exe file.我试图创建一个exe文件。
I have several ui files, of which I tried to make user_view_ui.py, which acts as a main_window, an executable file.我有几个 ui 文件,其中我尝试制作 user_view_ui.py,它充当 main_window,一个可执行文件。
Step 1) user_view_ui.py步骤 1) user_view_ui.py
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, relative_path)
form_ui = uic.loadUiType("ui\\user_view.ui")[0]
class UserViewUi(QMainWindow, form_ui):
...
And, I added the "resource_path" function in the others python files.而且,我在其他 python 文件中添加了“resource_path”函数。
Step2) I modified user_view_ui.spec file. Step2) 我修改了 user_view_ui.spec 文件。
ui_list = ['.\\ui\\user_view.ui', '.\\ui\\change_list_view.ui', '.\\ui\\move_to_another_changelist.ui', '.\\ui\\login.ui', '.\\ui\\user_settings.ui']
a = Analysis(['user_view_ui.py'],
pathex=[],
binaries=[],
datas=ui_list,
but, when I execute the "pyinstaller --onefile user_view_ui.spec", below the errors occur.但是,当我执行“pyinstaller --onefile user_view_ui.spec”时,会出现以下错误。
Traceback (most recent call last):
File "c:\users\appdata\local\programs\python\python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\appdata\local\programs\python\python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\AppData\Local\Programs\Python\Python36\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
File "c:\users\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\__main__.py", line 124, in run
run_build(pyi_config, spec_file, **vars(args))
File "c:\users\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\__main__.py", line 58, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "c:\users\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\building\build_main.py", line 803, in main
build(specfile, distpath, workpath, clean_build)
File "c:\users\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\building\build_main.py", line 725, in build
exec(code, spec_namespace)
File "user_view_ui.spec", line 20, in <module>
noarchive=False)
File "c:\users\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\building\build_main.py", line 287, in __init__
for name, pth in format_binaries_and_datas(datas, workingdir=spec_dir):
File "c:\users\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\building\utils.py", line 506, in format_binaries_and_datas
for src_root_path_or_glob, trg_root_dir in binaries_or_datas:
ValueError: too many values to unpack (expected 2)
In your .spec file the datas field expects a list of tuples containing the path to data file and the target folder it should be copied into at execution time.在您的 .spec 文件中,datas 字段需要一个元组列表,其中包含数据文件的路径以及在执行时应将其复制到的目标文件夹。
for example:例如:
ui_list = [
('.\\ui\\user_view.ui','.\\ui'),
('.\\ui\\change_list_view.ui','.\\ui'),
('.\\ui\\move_to_another_changelist.ui','.\\ui'),
('.\\ui\\login.ui', '.\\ui'),
('.\\ui\\user_settings.ui','.\\ui')
]
a = Analysis(['user_view_ui.py'],
pathex=[],
binaries=[],
datas=ui_list,
You can try using relative paths in your resource function.您可以尝试在资源函数中使用相对路径。
def resource_path(relative_path):
base_path = os.path.dirname(os.path.abspath(__file__))
uipath = os.path.join(base_path, relative_path)
return os.path.relpath(uipath, '.')
form_ui = uic.loadUiType(os.path.join(resource_path("ui"),"user_view.ui"))[0]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.