Pysimplegui: [مشكلة PyInstaller] فشل تنفيذ البرنامج النصي على استدعاء العملية الفرعية

تم إنشاؤها على ١٧ أكتوبر ٢٠١٩  ·  4تعليقات  ·  مصدر: PySimpleGUI/PySimpleGUI

نوع القضايا

حشرة

نظام التشغيل

ويندوز 7

نسخة بايثون

3.5

منفذ PySimpleGUI والإصدار

4.4.1

مستويات خبرتك في شهور أو سنوات

تجربة برمجة بايثون
1

خبرة في البرمجة بشكل عام
7

هل استخدمت إطار Python GUI آخر (tkiner ، Qt ، إلخ) سابقًا (نعم / لا جيد)؟
نعم

لقد أكملت هذه الخطوات:

  • [نعم] اقرأ التعليمات الخاصة بكيفية تقديم مشكلة
  • [نعم] بحثت في المستندات الرئيسية http://www.PySimpleGUI.org لمشكلتك
  • [] تم البحث في الملف التمهيدي عن المنفذ المحدد الخاص بك إذا لم يكن PySimpleGUI (Qt ، WX ، Remi)
  • [] بحثت عن البرامج التجريبية المشابهة لهدفك http://www.PySimpleGUI.com
  • [] لاحظ أن هناك أيضًا برامج تجريبية تحت كل منفذ على GitHub
  • [نعم] قم بتشغيل البرنامج خارج مصحح الأخطاء (من سطر الأوامر)
  • [نعم] تم البحث في المشكلات (مفتوحة ومغلقة) لمعرفة ما إذا تم الإبلاغ عنها بالفعل

كود أو رمز جزئي يسبب المشكلة

أنا جديد في PySimpleGUI. عندما أستخدم العملية الفرعية للوحدة النمطية وتعبئتها py في exe ، فإنها تتعطل دائمًا مثل لقطة الشاشة أدناه. ولكن عندما أقوم بتشغيل ملف py مباشرة في cmd ، يكون الأمر جيدًا. لذا من فضلك أخبرني أي شخص كيف أصلحه؟ شكرا.

تعطل ملف Exe على Windows7 عند النقر فوق موافق:
enter image description here

SimpleDemoTestSubprocess.py:

import PySimpleGUI as sg
import subprocess


def runCommand(cmd, timeout=None):
    """ run shell command
    <strong i="38">@param</strong> cmd: command to execute
    <strong i="39">@param</strong> timeout: timeout for command execution
    <strong i="40">@return</strong>: (return code from command, command output)
    """

    prt('runCommand, cmd = ' + str(cmd))

    p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    output = ''

    prt('runCommand, communicate')
    out, err = p.communicate()
    prt('runCommand, wait')
    p.wait(timeout)

    prt(out)
    prt(err)

    return (out, err)


def prt(self, *args, sep=' ', end='\n', file=None):
    print()
    print(self, *args, sep=' ', end='\r\n', file=None)


# All the stuff inside your window.
layout = [
    [sg.Text('Some text on Row 1')]
    , [sg.Text('Enter something on Row 2'), sg.InputText()]
    , [sg.Button('Ok'), sg.Button('Cancel')]
    # , [sg.PopupScrolled('Hello From PySimpleGUI!', 'This is the shortest GUI program ever!')]
]

# Create the Window
window = sg.Window('Window Title', layout)
# Event Loop to process "events" and get the "values" of the inputs
while True:
    event, values = window.read()
    if event in (None, 'Cancel'):  # if user closes window or clicks cancel
        break
    if event in (None, 'Ok'):  # if user closes window or clicks cancel
        runCommand("ls")
    print('You entered ', values[0])

window.close()

حزمة py إلى exe:

# https://github.com/PySimpleGUI/PySimpleGUI/blob/master/DemoPrograms/Demo_EXE_Maker.py

import PySimpleGUI as sg
import subprocess
from shutil import copyfile
import shutil
import os

def prt(self, *args, sep=' ', end='\n', file=None):
    print()
    print(self, *args, sep=' ', end='\r\n', file=None)

def Launcher():
    sg.ChangeLookAndFeel('LightGreen')

    layout = [[sg.T('PyInstaller EXE Creator', font='Any 15')],
              [sg.T('Source Python File'), sg.In(key='_sourcefile_', size=(45, 1)),
               sg.FileBrowse(file_types=(("Python Files", "*.py"),))],
              [sg.T('Icon File'), sg.In(key='_iconfile_', size=(45, 1)),
               sg.FileBrowse(file_types=(("Icon Files", "*.ico"),))],
              [sg.Frame('Output', font='Any 15', layout=[[sg.Output(size=(65, 15), font='Courier 10')]])],
              [sg.ReadFormButton('Make EXE', bind_return_key=True),
               sg.SimpleButton('Quit', button_color=('white', 'firebrick3')), ]]

    window = sg.Window('PySimpleGUI EXE Maker',
                       auto_size_text=False,
                       auto_size_buttons=False,
                       default_element_size=(20, 1,),
                       text_justification='right')

    window.Layout(layout)

    # ---===--- Loop taking in user input --- #
    while True:
        (button, values) = window.Read()
        if button in ('Quit', None):
            break  # exit button clicked

        source_file = values['_sourcefile_']
        icon_file = values['_iconfile_']

        icon_option = '-i "{}"'.format(icon_file) if icon_file else ''
        source_path, source_filename = os.path.split(source_file)
        workpath_option = '--workpath "{}"'.format(source_path)
        dispath_option = '--distpath "{}"'.format(source_path)
        specpath_option = '--specpath "{}"'.format(source_path)
        folder_to_remove = os.path.join(source_path, source_filename[:-3])
        file_to_remove = os.path.join(source_path, source_filename[:-3] + '.spec')
        command_line = 'pyinstaller -wF "{}" {} {} {} {}'.format(source_file, icon_option, workpath_option,
                                                                 dispath_option, specpath_option)

        if button == 'Make EXE':
            try:
                prt('source_file: ' + str(source_file))
                prt('Making EXE... this will take a while.. the program has NOT locked up...')
                window.Refresh()

                prt('window.Refresh')
                window.Refresh()
                prt('Running command: {}'.format(command_line))
                runCommand(command_line)
                shutil.rmtree(folder_to_remove)
                os.remove(file_to_remove)
                prt('**** DONE ****')
            except Exception as e:
                # sg.PopupError('Something went wrong')
                prt("Launcher, Exception = " + e)


def runCommand(cmd, timeout=None):
    """ run shell command
    <strong i="6">@param</strong> cmd: command to execute
    <strong i="7">@param</strong> timeout: timeout for command execution
    <strong i="8">@return</strong>: (return code from command, command output)
    """

    prt('runCommand, cmd = ' + str(cmd))

    p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    output = ''

    prt('runCommand, communicate')
    out, err = p.communicate()
    prt('runCommand, wait')
    p.wait(timeout)

    prt(out)
    prt(err)

    return (out, err)

if __name__ == '__main__':
    Launcher()

التعليق الأكثر فائدة

تم حلها عن طريق التغيير إلى هذا:

p = عملية فرعية.

ال 4 كومينتر

هذه مشكلة في PyInstaller. أفترض أن كل شيء يعمل بشكل جيد إذا لم تقم بتحويله إلى ملف EXE. في الماضي لم أتمكن من تحويل البرامج التجريبية للمشغل التي ستجدها هنا على GitHub إلى ملفات EXE بسبب مشاكل PyInstaller.

أقترح التحقق من stackoverflow أو في أي مكان آخر حول المشكلة الأكثر عمومية لمكالمات Subprocess و PyInstaller.

إذا قمت بإزالة كل كود PySimpleGUI وقمت فقط بالاتصال باستدعاء العملية الفرعية من ملف EXE الخاص بك ، فهل هناك مشاكل في ذلك؟ هل يمكنك محاولة ترميز ذلك بجد وإجراء اختبار؟

"أفترض أن كل شيء يعمل بشكل جيد إذا لم تقم بتحويله إلى ملف EXE"
نعم إنه كذلك.

"إذا قمت بإزالة كل كود PySimpleGUI واستدعيت استدعاء العملية الفرعية من ملف EXE الخاص بك ، فهل هذا به مشاكل؟"
حسنًا ، لقد قمت بتقطيع جميع رموز PySimpleGUI ، ولا يزال يتعطل. لذلك لا علاقة له بـ PySimpleGUI :)

فهل دعم PySimpleGUI حزم EXE الأخرى ، بدلاً من pyinstaller؟

تم حلها عن طريق التغيير إلى هذا:

p = عملية فرعية.

شكرا!!!!!!!!!

لقد كنت أحاول حل هذه المشكلة لبعض الوقت الآن. أنا أقدر لك حقًا ليس فقط البحث وإيجاد حل ، ولكن أيضًا العودة ونشره. في غاية الامتنان!

هل كانت هذه الصفحة مفيدة؟
0 / 5 - 0 التقييمات