【问题标题】:importing pywinauto on XP vs 7在 XP vs 7 上导入 pywinauto
【发布时间】:2013-12-18 22:58:21
【问题描述】:

我无法在 XP 上导入 pywinauto

我有一台运行 Windows 7 的计算机和一台运行 XP 的 VM。两者都有几乎相同的 Python 版本。

这里是每个环境中 Python27 文件夹之间差异的图片:http://i.stack.imgur.com/ao4R7.png

这些似乎是无关紧要的差异,尤其是在涉及到有问题的包装时。

如果我在 XP VM 上尝试import pywinauto,我会得到以下信息:

>>> import pywinauto.controls
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\pywinauto\__init__.py", line 28, in <module>
    import findwindows
  File "C:\Python27\lib\site-packages\pywinauto\findwindows.py", line 37, in <module>
    import controls
  File "C:\Python27\lib\site-packages\pywinauto\controls\__init__.py", line 33,in <module>
    import win32_controls
  File "C:\Python27\lib\site-packages\pywinauto\controls\win32_controls.py", line 31, in <module>
    from pywinauto import win32functions
ImportError: cannot import name win32functions
>>>

我没有尝试重新安装pywinautopywin32。在我尝试之前,我只想知道 pywinauto 在 XP 和 7 之间是否存在任何问题?还是在原生窗口和虚拟机之间?

【问题讨论】:

  • 请指定 Python2.X 32 位还是 64 位? pywinauto 在 Python 64 位下存在一些结构大小的问题。我在 Wondows 7 64bit 上成功使用 Python2.7 32bit + pywinauto。
  • 它们都是 32 位 2.7。我要回答我自己的问题,如果你看一下并告诉我我做了什么,我会很高兴的,我不知道它为什么有效,但它确实有效。

标签: python windows virtual-machine pywinauto


【解决方案1】:

好吧,我想我想通了,虽然我不知道为什么。我的问题是我原来的问题的根本原因是我得到了

sre_constants.error nothing to repeat

当我试图在 XP 虚拟环境中编译我的程序时。造成这种情况的原因是在第 110 行的C:\Python27\Lib\site-packages\pywinauto\tests\asianhotkey.py

_asianHotkeyRE = re.compile (r"""
    \(&.\)      # the hotkey
    (
        (\t.*)|     # tab, and then anything
        #(\\t.*)|   # escaped tab, and then anything
        (\(.*\)     # anything in brackets
    )|
    \s*|            # any whitespace
    :|              # colon
    (\.\.\.)|       # elipsis
    >|              # greater than sign
    <|              # less than sign
    (\n.*)          # newline, and then anything
    \s)*$""", re.VERBOSE)

我什至无法在我的虚拟 XP 环境中以自己的脚本运行它。如果我删除其中任一行中的*,它将运行

\s*|            # any whitespace

\s)*$""", re.VERBOSE)

我不知道为什么会这样,只是实验结果。

无论如何,据我所知,变量_asianHotkeyRE 在整个包中只使用一次;在同一文件的第 (133) 行:

found = _asianHotkeyRE.search(text)

所以我把那两组代码改成了

pattern = r"""
    \(&.\)      # the hotkey
    (
        (\t.*)|     # tab, and then anything
        #(\\t.*)|   # escaped tab, and then anything
        (\(.*\)     # anything in brackets
    )|
    \s*|            # any whitespace
    :|              # colon
    (\.\.\.)|       # elipsis
    >|              # greater than sign
    <|              # less than sign
    (\n.*)          # newline, and then anything
    \s)*$"""

 found = re.search(pattern,text)

关于使用正则表达式编译的一些东西不喜欢这种模式的格式。也许安装在该虚拟机上的re 版本不是最新的或什么?

长话短说,它是固定的。我不知道为什么,如果有人可以尝试使用他们自己的任何类型的虚拟环境来重现该问题,我会很高兴。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-03
    • 1970-01-01
    • 2011-03-21
    相关资源
    最近更新 更多