【问题标题】:Python 2.7 : exe file created from pyinstaller doesnt workPython 2.7:从 pyinstaller 创建的 exe 文件不起作用
【发布时间】:2019-09-15 23:25:58
【问题描述】:

我跟随 this article 使用 pyinstaller 创建了我的 run.exe 文件。我按预期在 dist 文件夹中获取了我的 exe 文件,没有任何错误。但是当我双击exe文件时,什么也没有发生。当我从命令提示符运行 exe 文件时,出现以下错误:

Traceback (most recent call last):
  File "run.py", line 2, in <module>
  File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 395, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\PySimpleGUI27\__init__.py", line 2, in <module>
  File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 395, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\PySimpleGUI27\PySimpleGUI27.py", line 14, in <module>
  File "site-packages\future\standard_library\__init__.py", line 459, in install_aliases
ImportError: No module named UserList
[16016] Failed to execute script run

我不明白这个错误。我的脚本中没有任何模块名称 Userlist。以下是我的脚本:

import PySimpleGUI27 as sg
import parse

layout = [               
    [sg.Text('A2L File', size=(15, 1), auto_size_text=False, justification='right'),      
     sg.InputText('',key='_a2l_'), sg.FileBrowse(file_types=(("A2L File", "*.a2l"),))],
    [sg.Text('Signals Lexicon', size=(15, 1), auto_size_text=False, justification='right'),      
     sg.InputText('',key='_sigLex_'), sg.FileBrowse(file_types=(("Excel File", "*.xlsx"),))],
    [sg.Text('Parameters Lexicon', size=(15, 1), auto_size_text=False, justification='right'),      
     sg.InputText('',key='_parLex_'), sg.FileBrowse(file_types=(("Excel File", "*.xlsx"),))],
    [sg.Text('Module Name', size=(15, 1), auto_size_text=False, justification='right'),      
     sg.InputText('X',key='_module_'), sg.FolderBrowse()],           
    [sg.Submit(), sg.Cancel()],
    [sg.Output(size=(60, 20))]  
]
window = sg.Window('A2L Parser', default_element_size=(40, 1)).Layout(layout)

values_dict={}
while True:
    button, values_dict = window.Read()
    if button=="Cancel" or button is None:
        break
    elif button=='Submit' and (not any(value == '' for value in values_dict.values())):   
        parse.parser(values_dict['_a2l_'], values_dict['_sigLex_'], values_dict['_parLex_'],window)

    else:
        sg.Popup("Please select files")  

window.Close()

当我从可视化代码运行该脚本时,该脚本有效,因此脚本中没有错误。在这个脚本中,我正在导入我自己的脚本 parse。 有人能解释一下exe文件有什么问题吗?

更新:我发现我必须在我的脚本中添加这些缺失的模块。但是在添加每个模块后,我收到另一个缺少模块的错误。有没有办法一次性找到所有缺失的模块?

【问题讨论】:

    标签: python windows module exe pyinstaller


    【解决方案1】:

    根据错误,解决方法如下:

    1. 使用任何文本编辑器打开此site-packages\future\standard_library\__init__.py 文件

    2. 第 459 行应该是“__import__(oldmodname)”并且在函数“install_aliases()”中

    3. 只需在“__import__(oldmodname)”之前添加以下行:

        if 0:
            import UserList
            import UserString
            import UserDict
            import itertools
            import collections
            import future.backports.misc
            import commands
            import base64
            import __buildin__
            import math
            import reprlib
            import functools
            import re
            import subprocess
    
    1. 保存并关闭此文件。然后再试一次。

    为什么要加上上面几行,请参考https://github.com/pyinstaller/pyinstaller/issues/2820

    此解决方法对我有用。如果你觉得sn-p代码插入其他位置更好,请自行调整。

    【讨论】:

      猜你喜欢
      • 2019-08-25
      • 2019-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-05
      • 2019-07-18
      • 1970-01-01
      相关资源
      最近更新 更多