irakli
irakli

Reputation: 51

ModuleNotFoundError: No module named 'pynput'

I am writing some basic code in visual studio code and I am trying to use pynput, but when I import the module despite the fact that I installed it using pip it gives me this error:

ModuleNotFoundError: No module named 'pynput'

I have tried to install it using pip3, but it doesn't work I have also tried to install it using the path interpreter, but it still doesn't work This is the code:

from pynput.mouse import Button, Controller

mouse = Controller()

# Read pointer position
print('The current pointer position is {0}'.format(
    mouse.position))

Strange thing is that this code works in sublime text 3, but doesn't work in neither visual studio code nor cmd.

Thank you in advance.

Upvotes: 1

Views: 11663

Answers (4)

Hasitha Amarathunga
Hasitha Amarathunga

Reputation: 2005

Try this

pip uninstall pynput
pip install pynput

or

install pynput using conda

conda install pynput

Upvotes: 0

Daniel Long
Daniel Long

Reputation: 1647

Most IDEs create an "interpreter" for your project, which in python-speak means that the IDE set up a "virtual environment" for you. Virtual environments are great for managing dependencies across different projects. For example if you need one version of pynput for one project and a later version for another project, you can do this with two separate virtual environments, whereas if you installed pynput on your system, upgrading pynput would break your first project. More info on virtual environments

When you open command line and run pip install, this installs the package onto your system interpreter. You'll instead need to 'activate' your virtual environment and run the pip install there. You can find the path to your virtual environment by opening your interpreter settings in your IDE. Then follow these instructions to activate your virtual environment and run the pip install on your project interpreter.

Upvotes: 1

cavalcantelucas
cavalcantelucas

Reputation: 1382

if you are trying to run it from within the IDE, check the paths in witch it calls the python interpreter.

if it's pointing to any conda installation try conda install pynput instead

Upvotes: 1

Ethan J.
Ethan J.

Reputation: 46

Your package associations may be incorrect.

First, see where your IDE is running python. it should be something like C:\programData\Python

Reinstalling the python interpreter may fix this. Or try upgrading the pip, which uninstalls the old one, and pulls down the new one from the cloud. Open a CMD windows, and type the following command:

python -m pip install --upgrade pip --user

This will give you a fresh pip installation. Then try "pip install pynput"

If this does not solve the issue, uninstall your current interpreter, then go to python.org, and download and install the latest interpreter. Upgrade the pip.

Upvotes: 2

Related Questions