我正在尝试安装适用于 Python 的 SendKeys。
If I use
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)
^