Reputation: 11
Terminal saying pyautogui is already installed, yet not recognizing it as a command
Code throwing error: Import "pyautogui" could not be resolved
Disclaimer: I have virtually no experience in Python except for a basic syntax course, and I'm very much a noob.
I was trying to create a spam bot as a prank for a friend based off of this video. The code is very simple, but for some reason doesn't work. The terminal says the module installed successfully, yet does not recognize it as a command, and the code throws an import error. Here's the entire code below to reproduce:
import pyautogui, time
time.sleep(5)
f = open("lol", "r")
for word in f:
pyautogui.typewrite(word)
pyautogui.press("enter")
Upvotes: 1
Views: 760
Reputation: 11
You need to select a Python interpreter that will use the dependencies. The best way to do this in VSCode is by using a virtual environment.
This will install a virtual environment.
python -m venv .venv
Now, use CTRL+SHIFT+P to open the serach bar. Type 'interpreter'. Select the virtual environment that you just created.
Close your old terminal, and open a new terminal. The new terminal should have the name of your virtual environment in green. This means that you can install any dependencies, and they should be accessible from your code.
Upvotes: 1
Reputation: 9461
If you want to check the module version, use the command pip show <packagename>
, you can also get its location:
If it's in current used python environment, open Command Palette and choose Developer: Reload Window, the problem should go away:
Upvotes: 1