生成KivyMD应用程序的.exe文件而不出现控制台窗口的方法?

huangapple go评论60阅读模式
英文:

How to generate .exe of a kivymd application without console properly?

问题

我试图生成我的KivyMD代码的.exe文件。我编写了一个非常简单的代码,因为我正在尝试学习如何做到这一点。

我的代码如下:

from kivymd.app import MDApp
from kivymd.uix.label import MDLabel
from kivymd.uix.screen import Screen

class Demo(MDApp):
    def build(self):
        self.screen = Screen()

        self.l1 = MDLabel(
            text="My Label"
        )

        self.screen.add_widget(self.l1)
        return self.screen

if __name__ == "__main__":
    Demo().run()

非常简单。

所以我使用了一个.spec文件,如下所示:

# -*- mode: python ; coding: utf-8 -*-
import os
from kivy_deps import sdl2, glew
block_cipher = None
from kivymd import hooks_path as kivymd_hooks_path

current_path = os.path.abspath('.')
icon_path = os.path.join(current_path, 'imagens', 'icone.ico')

a = Analysis(['main.py'],
             pathex=[current_path],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[kivymd_hooks_path],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
          name='Eaton',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          icon=icon_path,
          console=False)

我的代码文件名为main.py,我的.spec文件名为main.spec。

所以我的问题是,当我使用console=True时,这个代码和.spec文件正常工作,并创建一个良好的.exe文件,但当我使用console=False时,应用程序返回错误。如果有人能帮助我,我将非常感激。

英文:

I'm trying to generating a .exe of my kivymd code. I have coded a really simple code, because i was trying to learn how to do this.

My code is as follows:

from kivymd.app import MDApp
from kivymd.uix.label import MDLabel
from kivymd.uix.screen import Screen
 
class Demo(MDApp):
    def build(self):
        self.screen = Screen()
         
        self.l1 = MDLabel(
            text = "My Label"
        )

        self.screen.add_widget(self.l1)
        return self.screen 
 
if __name__ == "__main__":
    Demo().run()

Really simple.
So i'm using a .spec like this:

# -*- mode: python ; coding: utf-8 -*-
import os
from kivy_deps import sdl2, glew
block_cipher = None
from kivymd import hooks_path as kivymd_hooks_path

current_path = os.path.abspath('.')
icon_path = os.path.join(current_path, 'imagens', 'icone.ico')

a = Analysis(['main.py'],
             pathex=[current_path],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[kivymd_hooks_path],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
          name='Eaton',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          icon=icon_path,
          console=False )

My code file name is main.py and my .spec is main.spec.
So my problem is, when I use the console=True, this code and .spec works fine and create a good .exe, but when I use console=False the aplication returns error.
If someone can help me I will be very thankful.

答案1

得分: 0

好的,我只翻译您提供的部分:

"Ok, I just solve the problem by deleting python 3.9.7 and installing python 6.3.6."
翻译为:
"好的,我刚刚通过删除 Python 3.9.7 并安装 Python 6.3.6 来解决了这个问题。"

英文:

Ok, I just solve the problem by deleting python 3.9.7 and installing python 6.3.6.

huangapple
  • 本文由 发表于 2023年2月18日 00:45:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75487049.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定