我正在尝试安装SendKeys for Python。
如果我使用
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)
^
答案 0 :(得分:0)
下载.zip文件,解压缩并执行python setup.py install
答案 1 :(得分:0)
安装错误是由于缺少Visual Studio的组件引起的,并且通过更新Visual Studio的Python工具来解决。这可能是Windows上安装和更新的常见问题。
我还没有解决导入问题。我认为它与python版本有关,但我不确定。无论如何,我选择使用pyautogui,所以这个问题没有实际意义。