简体   繁体   English

无法使用 Python 和 PyQt5 创建 a.exe 文件

[英]Failing to create a .exe file with Python and PyQt5

I`m trying to make an executable from my python script called ProyectoNew.py .我正在尝试从名为ProyectoNew.py的 python 脚本创建一个可执行文件。 It works with a folder called "Imagenes" and another called "ModulosExternos" , and a PyQT5's.ui file like this:它适用于一个名为“Imagenes”的文件夹和另一个名为“ModulosExternos”的文件夹,以及一个像这样的 PyQT5's.ui 文件:

在此处输入图像描述

Here`s the Code posted in GitHub: https://github.com/TheFlosh/ProyectoSoftware.git这是 GitHub 中发布的代码: https://github.com/TheFlosh/ProyectoSoftware.git

I`ve tried to use Pyinstaller , Py2Exe and CXFreeze but it didn't worked.我尝试使用PyinstallerPy2ExeCXFreeze ,但没有成功。 Using each one of these modules to create a.exe file I've got the same result when I tried to execute it in another PC, as shown here:使用这些模块中的每一个来创建一个 .exe 文件,当我尝试在另一台 PC 中执行它时,我得到了相同的结果,如下所示:

左:使用 pyinstaller 后得到的结果 - 右:我需要展示的内容

On the LEFT of the picture you can see what I get after using pyinstaller (or Py2Exe), on the right you can see what I need to show.在图片的左侧,您可以看到使用 pyinstaller(或 Py2Exe)后得到的结果,在右侧,您可以看到我需要展示的内容。

Here are the modules that I use in my code ("ModulosExternos" is the folder where I put some particular modules that my code needs):以下是我在代码中使用的模块(“ModulosExternos”是我放置代码需要的一些特定模块的文件夹):

from PyQt5 import QtCore, QtGui, QtWidgets
import sys
import pyttsx3
from pyttsx3.drivers import sapi5   
import PyQt5                        
import sip                          
import os                          
from ModulosExternos import Boton_1,Boton_2,Boton_3,Boton_4,Boton_Final,Listas_Pictogramas, Frases_Completas

And here is the last part of it, to instantiate the GUI:这是它的最后一部分,用于实例化 GUI:

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    GUI = ProyectoNew()
    GUI.show()
    sys.exit(app.exec()) 

I`ve read a lot of posts on the internet that recommended creating Setup.Py file to initiate the process of creating an executable file of my project.我在互联网上阅读了很多建议创建Setup.Py文件以启动创建项目可执行文件的过程的帖子。 These are some examples of what I did with two of them:这些是我对其中两个所做的一些示例:

With CX_Freeze:使用 CX_Freeze:

import sys
import os
from cx_Freeze import setup, Executable

files = ['icono.ico','/Imagenes']

target = Executable(
    script = "/ProyectoNew.py",
    base = 'Win32GUI',
    )

#Setup 
setup(
    name = "Proyect2",
    version = "1.6",
    description = "Software",
    author = "----",
    options = {'build_exe': {'include_files' : files}},
    executables = [target]
    )

With Py2Exe:使用 Py2Exe:

from cx_Freeze import setup, Executable

setup(name = "Proyect2",
    version="1.0",
    description = "Software",
    executables = [Executable("ProyectoNew.py")],)

With Pyinstaller I typed: python --nowindowed --onefile ProyectoNew.py but I constantly got the same result as shown before.使用Pyinstaller ,我输入: python --nowindowed --onefile ProyectoNew.py但我不断得到与前面所示相同的结果。

I think that when I execute Pyinstaller , the.exe file doesn`t load the modules and the images that I use.我认为当我执行Pyinstaller时,.exe 文件不会加载我使用的模块和图像。 What am I missing while creating the file?创建文件时我缺少什么? What do I need to do to execute the.exe file in another PC?.我需要做什么才能在另一台 PC 上执行 .exe 文件?

I would prefer to use pyinstaller ,but using any one of these will help me.我更喜欢使用pyinstaller ,但使用其中任何一种都会对我有所帮助。

What's is wrong with that?那有什么问题? You get some kind of error?你得到某种错误? Please edit your question with that.请编辑您的问题。

With pyinstaller and this command, you should be able easily build an executable file:使用 pyinstaller 和此命令,您应该能够轻松构建可执行文件:

pyinstaller [FILE].py -w -F

This command generate a /dist folder with the neccesary files and.exe file to run此命令生成一个 /dist 文件夹,其中包含要运行的必需文件和 .exe 文件

*-w param is for do not provide a console window for standard i/o *-w 参数用于不为标准 i/o 提供控制台 window

*-F param is for one-file bundled executable You can check more paramshere *-F 参数用于一个文件捆绑的可执行文件您可以在此处查看更多参数

PD: Before, you need obviously install pyinstaller: PD:之前,您显然需要安装 pyinstaller:

pip install pyinstaller

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM