PyInstaller-PyInstaller不会编译导入的脚本

时间:2018-09-19 17:54:10

标签: python python-2.7 kivy pyinstaller

我正在尝试编译一个Python脚本,该脚本从另一个脚本接收数据并在Kivy屏幕上使用它,但是PyInstaller显然没有找到在我的主文件开头导入的另一个脚本。

启动.exe后,Kivy可以正常启动,请查看控制台窗口,但此后它会快速打开Kivy窗口并关闭。

主文件位于“ src”文件夹中。

有人知道我如何让PyInstaller查找和编译我的脚本吗?

我要编译的文件(Main.py):

#!/usr/bin/python
# -*- coding: utf8 -*-

from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
# from kivy.config import Config
from kivy.uix.button import Button
from kivy.uix.floatlayout import FloatLayout
from kivy.core.window import Window
from src.Controller.ModuloController import ModuloController
import multiprocessing
from screeninfo import get_monitors
import kivy.resources
import sys
import os


class Float(FloatLayout):

    def __init__(self, **kwargs):
        super(Float, self).__init__(**kwargs)
        self.modulos = ModuloController.listar()
        self.box = BoxLayout(orientation='vertical',
                             padding=[20, 20],
                             spacing=20)
        self.box.grid = Grid(self.modulos)
        self.add_widget(self.box)
        self.box.add_widget(self.box.grid)


class Grid(GridLayout):

    def __init__(self,
                 modulos,
                 **kwargs):
        super(Grid, self).__init__(**kwargs)
        # self.rows = 2
        self.cols = 2
        self.spacing = 20
        for modulo in modulos:
            if modulo.nome == 'Caixa':
                self.add_widget(Button(text=modulo.nome,
                                       on_press=self.abrir_caixa,
                                       font_size=36,
                                       background_normal='',
                                       background_color=[0/255.0,
                                                         75/255.0,
                                                         198/255.0,
                                                         1]))
            elif modulo.nome == 'Retaguarda':
                self.add_widget(Button(text=modulo.nome,
                                       on_press=self.abrir_retaguarda,
                                       font_size=36,
                                       background_normal='',
                                       background_color=[0/255.0,
                                                         75/255.0,
                                                         198/255.0,
                                                         1]))

    def abrir_caixa(self, t):
        m = multiprocessing.Process(target=ModuloController().iniciar,
                                    args=('Caixa',))
        m.start()

    def abrir_retaguarda(self, t):
        m = multiprocessing.Process(target=ModuloController().iniciar,
                                    args=('Retaguarda',))
        m.start()


class ACApp(App):

    def build(self):
        # Config.set('graphics', 'width', str(get_monitors()[0].width - 7))
        # Config.set('graphics', 'height', str(get_monitors()[0].height - 30))
        # Config.set('graphics', 'top', 30)
        # Config.set('graphics', 'left', 7)
        # Config.write()
        Window.size = [900, 450]
        Window.top = int(get_monitors()[0].height // 2 - Window.size[1] // 2)
        Window.left = int(get_monitors()[0].width // 2 - Window.size[0] // 2)
        Window.clearcolor = (1, 1, 1, 1)
        return Float()


class AcInterface(object):

    def iniciar(self):
        ACApp().run()


def resourcePath():
    '''Returns path containing content - either locally or in pyinstaller tmp file'''
    if hasattr(sys, '_MEIPASS'):
        return os.path.join(sys._MEIPASS)

    return os.path.join(os.path.abspath("."))


if __name__ == '__main__':
    multiprocessing.freeze_support()
    kivy.resources.resource_add_path(resourcePath())  # add this line
    # main = multiprocessing.Process(target=AcInterface().iniciar)
    # main.start()
    ACApp().run()

我修改了PyInstaller生成的.spec并重新编译:

    # -*- mode: python -*-

from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.floatlayout import FloatLayout
from kivy.core.window import Window
import multiprocessing
from screeninfo import get_monitors
import kivy.resources
import sys
import os
from kivy.deps import sdl2, glew
from kivy.tools.packaging.pyinstaller_hooks import get_deps_minimal, get_deps_all, hookspath, runtime_hooks


block_cipher = None


a = Analysis(['JC_AC_App.py'],
             pathex=['C:\\Users\\sony\\Downloads\\Scripts-Python\\AC\\src',
             'C:\\Users\\sony\\Downloads\\Scripts-Python\\AC\\src\\Controller'],
             binaries=[],
             datas=[],
             hookspath=hookspath(),
             runtime_hooks=runtime_hooks(),
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False,
             **get_deps_all())
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='JC_AC_App',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
               strip=False,
               upx=True,
               name='JC_AC_App')

我试图将“ from src.Controller.ModuloController import ModuloController”放在.spec中,但是它导致以下错误:

965 WARNING: stderr:   File "<string>", line 7, in <module> ImportError: No module named src.Controller.ModuloController
967 WARNING: stderr: ImportError: No module named src.Controller.ModuloController

我已经警告过有关Windows中Kivy编译和多处理的错误。

0 个答案:

没有答案