问题
I have a problem and I can't find anything to help.The idea is that I can't import pynput. I did the pip install and this is what it shows:
> Traceback (most recent call last):
File "sb.py", line 1, in <module>
from pynput.keyboard import Key, Controller
ImportError: No module named pynput.keyboard
I tried again pip install pynput and it shows
Requirement already satisfied
Here is the code, i don't know if it helps but there you go:
from pynput.keyboard import Key, Controller
def game():
keyboard = Controller()
if key.press():
s = Sound()
s.read("Cymatics - Guitar Chord Loop 2 - 128 BPM Dmaj")
s.play()
print "Welcome to soundboard"
print "You will see a list of sound names, just write the name of it"
print "If you want to stop it type stop"
print "Type start"
start = input()
if start.lower() == "start":
while True:
game()
else:
print "Ups, try again.."
Thanks in advance
回答1:
How are you running the file? When you do python3 nameofyourprogram.py you should use pip3 install pynput
回答2:
Last time I had this issue, it was because I had installed the module using pip for a given version of python (lets say 2.7), but I was running my script using python 3.6. Try to check the versions.
来源:https://stackoverflow.com/questions/55242218/importerror-no-module-named-pynput-keyboard