在某些系统上由 pywinauto 引起的 Py2Exe 错误:“AttributeError: 'module' object has no attribute 'CUIAutomation"; [英] Py2Exe error caused by pywinauto on some systems: "AttributeError: 'module' object has no attribute 'CUIAutomation"

查看:78
本文介绍了在某些系统上由 pywinauto 引起的 Py2Exe 错误:“AttributeError: 'module' object has no attribute 'CUIAutomation";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向几个 Windows 2012 R2 推出一个 EXE,其中大部分都运行良好.然而,似乎在相同的条件下,我有一些吐出错误: AttributeError: 'module' object has no attribute 'CUIAutomation'

I'm rolling out an EXE to several Windows 2012 R2's and the majority of them work just fine. However, seemingly under the same condition, I have a handful that spit out the error: AttributeError: 'module' object has no attribute 'CUIAutomation'

我曾经有过:

from pywinauto.findwindows import find_window
from pywinauto.win32functions import SetForegroundWindow

我也尝试添加:

import pywinauto

但这并没有多大作用.我还尝试更改代码,因此我没有使用 find_window,而是使用了完整的 pywinauto.findwindows.SetForegroundWindow 相同.

But that didn't do much. I also attempted to change the code so instead of using find_window I used the full pywinauto.findwindows. Same for SetForegroundWindow.

我的进口清单.对不起,如果它马虎或多余,我是新手,正在自学.

My import list. Sorry if it's sloppy or redundant, I'm new and self-learning.

import requests
import json
import os
import winshell
import sys
import re
import subprocess
import win32gui
import win32api
import win32con
import os.path
import ctypes
import fnmatch
import urllib2
import shutil
import psutil
import pywinauto
from pywinauto.findwindows import find_window
from pywinauto.win32functions import SetForegroundWindow
from pathlib import Path
from win32com.client import Dispatch
from stat import S_IREAD, S_IRGRP, S_IROTH
from time import sleep
from bs4 import BeautifulSoup

我在脚本中使用 pywinauto 的唯一地方是:

Really the only place I'm using pywinauto in my script is:

SetForegroundWindow(find_window(title_re = r'Server*'))

某些系统在启动时出现 py2exe 错误:

py2exe error on launch for some systems:

File "SVMon.py", line 17, in <module>
File "c:\users\administrator\appdata\local\temp\pip-install-dm1p2f\PyInstaller\PyInstaller\loader\pyimod03_importers.py", line 395, in load_module
File "site-packages\pywinauto\__init__.py", line 89, in <module>
File "c:\users\administrator\appdata\local\temp\pip-install-dm1p2f\PyInstaller\PyInstaller\loader\pyimod03_importers.py", line 395, in load_module
File "site-packages\pywinauto\findwindows.py", line 42, in <module>
File "c:\users\administrator\appdata\local\temp\pip-install-dm1p2f\PyInstaller\PyInstaller\loader\pyimod03_importers.py", line 395, in load_module
File "site-packages\pywinauto\controls\__init__.py", line 36, in <module>
File "c:\users\administrator\appdata\local\temp\pip-install-dm1p2f\PyInstaller\PyInstaller\loader\pyimod03_importers.py", line 395, in load_module
File "site-packages\pywinauto\controls\uiawrapper.py", line 47, in <module>
File "c:\users\administrator\appdata\local\temp\pip-install-dm1p2f\PyInstaller\PyInstaller\loader\pyimod03_importers.py", line 395, in load_module
File "site-packages\pywinauto\uia_defines.py", line 181, in <module>
File "site-packages\pywinauto\uia_defines.py", line 169, in _build_pattern_ids_dic
File "site-packages\pywinauto\uia_defines.py", line 50, in __call__
File "site-packages\pywinauto\uia_defines.py", line 63, in __init__
AttributeError: 'module' object has no attribute 'CUIAutomation'
[1928] Failed to execute script SVMon

推荐答案

我最终通过使用 PyInstaller 解决了这个问题,但我不确定是什么技巧,但我添加了我能想到的所有隐藏导入:

I ended up fixing this by using PyInstaller and I'm not exactly sure what did the trick but I added every hidden import I could think of:

pyinstaller --hidden-import comtypes.gen.UIAutomationClient --hidden-import comtypes --hidden-import comtypes.gen --hidden-import comtypes.patcher --hidden-import comtypes.GUID --hidden-import pywinauto --hidden-import pywinauto.CUIAutomation --hidden-import pywinauto.findwindows --hidden-import pywinauto.findwindows VPSMonitor.py --onefile --clean

这篇关于在某些系统上由 pywinauto 引起的 Py2Exe 错误:“AttributeError: 'module' object has no attribute 'CUIAutomation";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆