I am trying to make a python project that requires detection of keys from the user, I have tried installing the python package keyboard by running pip3 install keyboard
in cmd
, it ends up installing the keyboard package but when I type import keyboard into python and run the project it keeps showing an error message of: No module named 'keyboard'
, even though I installed it.
I am using python 3.10.4 on windows 10 home. I use spyder as my programming editor.
I have tried uninstalling python and re-installing it but that didn't work. I have tried uninstalling the module and re-installing it but that didn't work. I have tried repairing python but that didn't work.
Code:
https://i.stack.imgur.com/a4OFu.png
https://i.stack.imgur.com/StQjR.png
CodePudding user response:
I managed to solve this problem by downloading and installing miniconda: (https://docs.conda.io/en/latest/miniconda.html)
I then searched for anaconda prompt in the windows search bar,
then I created a new environment using the command conda create -n spyder2 python=3
instead of spyder2 you can name it what ever you want.
Then I activated the environment by using the command conda activate spyder2
replace spyder2 with your chosen environment name.
Then I added the necessary spyder-kernels by using the command..
pip install spyder-kernels
Then I added my chosen package which in this case was the keyboard package, I used the command pip install keyboard
replace keyboard with your own package name.
You can now close the anaconda prompt by pressing the exit button or typing exit
in the prompt.
You now want to open spyder and click on the tools tab at the top of spyder, now press the preferences in the drop down menu when shown, then click on python interpreter in the list of options when shown, under the python interpreter section click the second check box, then click on the drop down menu and select the environment that you had made in the anaconda prompt, then click the apply button located at the bottom and then click the ok button located next to the apply button.
Now restart spyder and you have finished creating your new environment and can now start using 3rd party packages and modules.
Note: If you are wanting to add new packages or modules, open the anaconda prompt and activate the environment that you had just made using the code provided earlier on in this tutorial, then use the pip install YourPackageName
command and your done.