python - 安装和导入 SendKeys 时出现问题 -- 更新

标签 python visual-studio sendkeys

我正在尝试安装适用于 Python 的 SendKeys。

如果我使用

pip install SendKeys

我收到链接错误:

 _sendkeys.c(150): warning C4013: 'Py_InitModule' undefined; assuming extern returning int 
 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED, \10.0.10240.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64" "/LIBPATH:C:\Program Files (x86)
LINK : error LNK2001: unresolved external symbol PyInit__sendkeys
build\temp.win-amd64-3.5\Release\_sendkeys.cp35-win_amd64.lib : fatal error LNK1120: 1 unresolved externals
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\link.exe' failed with exit status 1120

如果我下载 64 位 .whl 并尝试在本地使用 pip 安装它,我会得到:

sendkeys-0.3-cp27-none-win_amd64.whl is not a supported wheel on this platform.

如果我尝试 32 位版本,我会得到同样的错误。

pip 是最新的。我的 Visual Studio 设置有问题吗?

--更新--

在 Visual Studio 中更新 Python 模块后,我能够安装 SendKeys,但当我尝试导入 SendKeys 时出现以下错误

>>> import SendKeys
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\...\AppData\Continuum\Anaconda3\lib\site-packages\sendkeys-0.3-py3.5-win-amd64.egg\SendKeys.py", line 419
    except (ValueError,AssertionError),e:

SyntaxError: invalid syntax

抛出错误的代码在 main 中:

def main(args=None):
 import getopt

 if args is None:
    args = sys.argv[1:]

 try:
    opts,args = getopt.getopt(args, 
        "hp:d:f:", ["help","pause","delay","file"])
 except getopt.GetoptError:
    usage()

 pause=0
 delay=0
 filename=None

 for o, a in opts:
    if o in ('-h','--help'):
        usage()
    elif o in ('-f','--file'):
        filename = a
    elif o in ('-p','--pause'):
        try:
            pause = float(a)
            assert pause >= 0
        except (ValueError,AssertionError),e:
            error('`pause` must be >= 0.0')
    elif o in ('-d','--delay'):
        try:
            delay = float(a)
            assert delay >= 0
        except (ValueError,AssertionError),e:
            error('`delay` must be >= 0.0')

 time.sleep(delay)
                                  ^

最佳答案

安装错误是由于缺少 Visual Studio 组件引起的,已通过更新 Visual Studio 的 Python 工具修复。这可能是 Windows 上安装和更新的常见问题。

我还没有解决导入问题。我认为这与 python 版本有关,但我不确定。无论如何,我选择使用 pyautogui 来代替,所以这个问题没有实际意义。

关于python - 安装和导入 SendKeys 时出现问题 -- 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40411145/

相关文章:

python - Matplotlib 颤动图 : argument order

python - 机械化 : SSL: CERTIFICATE_VERIFY_FAILED

asp.net - 从 Asp.Net 4 项目进入引用的 .Net 3.5 程序集

selenium - 在 Selenium 中, sendKeys() 和 setValue() 方法究竟有何不同?

c# - 将键盘键发送到在同一项目上启动的另一个应用程序

VBScript 发送键“

python - 如何在 Python 中压缩一堆函数?

Netbeans 中的 Python 引用外部模块

c# - 如何在 Visual Studio 中为 mac 启用 VIM?

c++ - 关闭一个对话框并打开另一个对话框