0

XP无法导入pywinauto

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

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

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

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

>>> 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. 在我尝试之前,我只想知道 XP 和 7 之间的 pywinauto 是否有任何问题?还是在本机 Windows 和 VM 之间?

4

1 回答 1

0

Okay, I think I figured it out, although I have no idea why. My question was what I though was the root cause of my original problem which was that I got

sre_constants.error nothing to repeat

when I tried to compile my program in the XP virtual environment. The cause of this was in C:\Python27\Lib\site-packages\pywinauto\tests\asianhotkey.py at line 110.

_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)

I couldn't even run this in its own script in my virtual XP environment. It would run if I either removed the * in either one of these lines

\s*|            # any whitespace

or

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

I have no idea why that was the case, just experimental outcomes.

Anyway, as far as I could tell the variable _asianHotkeyRE is only used once in this whole package; at line (133) of this same file:

found = _asianHotkeyRE.search(text)

So I changed those two groups of code to

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)*$"""

and

 found = re.search(pattern,text)

Something about using regular expression compiling didn't like the formatting of this pattern. Maybe the version of re that is installed on that virtual machine isn't up to date or something?

So long story short, it's fixed. I don't know why and I would love it if someone could try to reproduce the issue using their own virtual environments of any kind.

于 2013-12-20T21:47:09.997 回答