ModuleNotFoundError: No module named 'pynput' - python

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.

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.

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

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.

Try this
pip uninstall pynput
pip install pynput
or
install pynput using conda
conda install pynput

Related

I installed package, but python said No moudel <name-packages> any packages I try to install it

I try using pip and pip3 and python -m pip and all ways to install. The terminal says the packages already installed after the first try to install, but when I try to import the package I had error no moudel name.
I feel the peoblem coming form here
But I am not sure
And when I go to packages in pycharm I saw the packages not installed
I appreciate your help
I'm assuming you're using windows.
It looks like you install the package directly in your system and PyCharm are using a virtual environment to run your code.
Try to activate this virtual environment before run your code:
source venv\Scripts\activate
If you see "(venv)" at the begging of your terminal prompt the virtual environment are activated.
Run pip list to check what packages are installed in there and probably you have to install your package another time, this time in your activated virtual environment. The official documentation will help to understand how and why use virtual environments.
After that you can try to run your code directly from the terminal:
python your_file.py
Install the packages from PyCharm itself, not the terminal as I think pycharm is running a virtual environment.
Maybe you can follow https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html#packages-tool-window

Pip update the wrong python folder

The first time I have installed Python on my machine, it was Spyder with Anaconda.
But, with this version, I wasn't able to install pyodbc.
So, I have install Visual Studio Code and everything works fine
But today, I have tried to update some libraries (like certify or scipy) but each time I use pip install, I update my Anaconda folder and not my WindowsApps folder.
So, when I use PIP, how to update the Windows folder and not Anaconda. And also how to remove Anaconda from my computer. In my Windows Settings, I have no app related to Anaconda (weird)
Check your path, and which pip executable is being executed.
If you run it with the full path to your install in WindowsApps, then it should detect and update that version.
You can check which pip you are using with the command of pip --version.
Press win to open the start menu and search uninstall-a to find the Uninstall-Anaconda3.exe or open the control-panel to uninstall it. Like the official docs recommended.

How can I point my Spyder IDE to the path where all packages are installed?

I had a massive crash today and lost a lot of work. I couldn't start Spyder after many attempts; even tried 'spyder --reset'. Nothing worked. I decided to download a new version of Anaconda and start over. Now, I'm trying to figure out why I can't run packages.
If I run this: import pyodbc
I get this: ModuleNotFoundError: No module named 'pyodbc'
So, I go to the command prompt to pip install pyodbc...and apparently it's already installed...
When I navigate to that path, I can see the package
...but Spyder is still telling me it's not installed. What's an easy fix for this?
i had similar crash problems on Windows 10, what I learned is that I had several non-conda versions of python on my PC, and I used 'pip install' in my environments so it messed up with conda packages and it stop working.
What I did is that I uninstalled anaconda and non-conda python, cleaned up registry from python mentions, installed fresh new miniconda, and 'conda install spyder' in the new env, conda have created new folder
C:\Users\~~~\.spyder-py3\
Inside of it I found "spyder.ini" file, where incorrect variable was set:
"spyder_pythonpath = "
I changed it from
['C:\Users\~~~\anaconda3\pkgs',
'C:\Users\~~~\anaconda3\envs']
to
['C:\Users\~~~\miniconda3\pkgs',
'C:\Users\~~~\miniconda3\envs']
Please Upvote it take so much time
First open Spyder and click Tools --> Open command prompt.
You should see the Command Window appear in the bottom right of your screen.
Here we install the Python package seaborn as an example.
# In the command line, type pip install seaborn
C:\Users\your_username\Documents\Python Scripts>pip install seaborn
This will install seaborn on your machine.
Note:
To upgrade the pip version on Windows, type python -m pip install --upgrade pip on the command line.
On Windows, all of your Python packages can be found in the directory of C:\Anaconda2\Lib\site-packages if you use the default path when you install Anaconda.
To upgrade the pip version on OS X, type pip install --upgrade pip on the command line.

unable to successfully import/ use pyautogui library in my IDE

I am attempting to use a small script to move my mouse slightly every minute or two to make the appearance that I am sitting at my desk (dont tell my boss please)
is anyone able to assist in why this might be happening?
from my command prompt I was able to successfully install pip install pyautogui
note, that: pip3 install autogui was not recognized
once I opened up pycharm, I ran the code, and got the below error:
ModuleNotFoundError: No module named 'pyautogui'
I also checked to make sure I had python 3 in command line using pip version = anaconda3\lib\site-packages\pip (python 3.7)
**full code below for reference
import pyautogui
import time
import sys
from datetime import datetime
pyautogui.FAILSAFE = False
numMin = None
if ((len(sys.argv)<2) or sys.argv[1].isalpha() or int(sys.argv[1])<1):
numMin = 1
else:
numMin = int(sys.argv[1])
while(True):
x=0
while(x<numMin):
time.sleep(60)
x+=1
for i in range(0,200):
pyautogui.moveTo(0,i*4)
pyautogui.moveTo(1,1)
for i in range(0,3):
pyautogui.press("shift")
print("Movement made at {}".format(datetime.now().time()))
https://github.com/Johnson468/Stay-Awake
for reference - i am using windows
You cannot import pyautogui from python 3 interpreter in pycharm because it is not installed.
When you ran pip install pyautogui you installed it on your python2.7 environment.
When you tried to installed it with pip3 you ran anaconda's pip (accordint to you error).
you can check which pip is used inside the CMD with the command where pip3.
If it is not found you can try running it like this: python -m pip but make sure you are running python3!
I highly recommend installing everything in venv virtual environment to make sure nothing is missing and you don't have any dependencies issues.
Or if you are new to python, uninstall all different instances and only keep one (probably python3 in your case), or edit you PATH in Windows
Furthermore I'm pretty sure when you are running pip from your console you are using another instance of it on your computer then the one you set as interpreter on pycharm, hence you couldn't use pip3 at all.
If none of the above helped, please add more details yo your question and I'll edit the answer.
Summary: You have a few instances of python installed on your computer (at least one of python2.7 and one of anaconda), when you run python or pip from the CMD if refers to the python2.7 one.
But when you chose an interpreter for you project in Pycharm you chose a python3 instance, which is obviously doesn't contain pyautogui.
Make sure you are using the right python instance when setting it up in Pycharm and when installing packages.
I answered this question recently: Problem with Python modules import on Mac
The issue might be that you don't have pip installed.
I know most Mac's have pip and Python pre-installed, but it wouldn't hurt to try: sudo easy_install pip
If this doesn't seem to be the issue, you might be running the pip install packageName in the wrong directory.
You will need to access your scripts folder in python and run the pip install packageName command in there. Here is a resource which should help you reach that directory: https://datatofish.com/install-package-python-using-pip/
This was answered for a Mac, but switching the commands to another OS shouldn't be hard. Just make sure pip is installed and that you're installing in the right directory.

Installing python packages from cmd in windows 10

I recently downloaded anaconda and added it to the environment variables following the question below:
anaconda - path environment variable in windows.
I added it as
C:\Users\My_User\Anaconda3
The thing is, I've been trying to install some packages using either pip or conda without luck.
For instance:
pip install seaborn
Return the following
Error output
Does somebody know how can I enable package installation either through pip or conda?
I'm very new to executing commands through cmd and couldn't figure out a better way to type my question, sorry about that
Step 1:
Open Anaconda Navigator
navigator
Step 2:
Go to Environments and select All packages, to view the list of all packages installed.
environment packages
Step 3:
Look for seaborn in the Search bar
search bar
Install it and see if that works.
If it doesn't then try creating a new environment and installing the seaborn package there. create new environment
Try
python -m pip install seaborn
You're getting this error because you're running pip from inside of the Python interpreter when you should be running it from the command line. To exit the Python interpreter, press ctrl+d. Then, make sure you have pip installed and in your PATH and you can try again.

Categories