问题
I am trying to install SendKeys for Python.
If I use
pip install SendKeys
I get a link error:
_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
If I download the 64-bit .whl and try to install it with pip locally I get:
sendkeys-0.3-cp27-none-win_amd64.whl is not a supported wheel on this platform.
I get the same error if I try the 32-bit version.
pip is up to date. Is there something wrong with my Visual Studio setup?
--Update--
I was able to intall SendKeys after updating the Python module in Visual Studio, but I get the following error when I try to import 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
The code that throws the error is in 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)
^
回答1:
The installation error was caused by missing components of Visual Studio, and was fixed by updating the Python Tools for Visual Studio. That's probably a common problem for installation and updates on Windows.
I still have not fixed the import issue. I think it has to do with the python version, but I'm not sure. In any event, I've chosen to use pyautogui instead, so the issue is moot.
回答2:
Download .zip file, unzip and do python setup.py install
来源:https://stackoverflow.com/questions/40411145/trouble-installing-and-importing-sendkeys-update