尽管在终端中安装成功,但模块“pyautogui”未正确导入

问题描述

Terminal saying pyautogui is already installed,yet not recognizing it as a command

Code throwing error: Import "pyautogui" could not be resolved

免责声明:除了基本语法课程之外,我几乎没有 Python 经验,而且我是个菜鸟。

我试图创建一个垃圾邮件机器人,作为基于 this video 的朋友的恶作剧。代码很简单,但由于某种原因不起作用。终端说模块安装成功,但没有将其识别为命令,并且代码抛出导入错误。以下是要重现的完整代码

import pyautogui,time
time.sleep(5)
f = open("lol","r")
for word in f:
  pyautogui.typewrite(word)
  pyautogui.press("enter")

解决方法

如果你想查看模块版本,使用命令pip show <packagename>,你也可以得到它的位置:

enter image description here

如果是在当前使用的python环境中,打开Command Palette并选择Developer: Reload Window,问题应该会消失:

enter image description here