简体   繁体   English

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

[英]Module "pyautogui" is not importing correctly despite installing successfully in terminal

Terminal saying pyautogui is already installed, yet not recognizing it as a command终端说 pyautogui 已安装,但未将其识别为命令

Code throwing error: Import "pyautogui" could not be resolved代码抛出错误:无法解析导入“pyautogui”

Disclaimer: I have virtually no experience in Python except for a basic syntax course, and I'm very much a noob.免责声明:除了基本语法课程外,我几乎没有 Python 的经验,而且我是一个菜鸟。

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")

You need to select a Python interpreter that will use the dependencies.您需要 select 一个将使用依赖项的 Python 解释器。 The best way to do this in VSCode is by using a virtual environment.在 VSCode 中执行此操作的最佳方法是使用虚拟环境。

This will install a virtual environment.这将安装一个虚拟环境。 python -m venv.venv

Now, use CTRL+SHIFT+P to open the serach bar.现在,使用 CTRL+SHIFT+P 打开搜索栏。 Type 'interpreter'.输入“解释器”。 Select the virtual environment that you just created. Select 您刚刚创建的虚拟环境。

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.这意味着您可以安装任何依赖项,并且应该可以从您的代码中访问它们。

If you want to check the module version, use the command pip show <packagename> , you can also get its location:如果要查看模块版本,使用命令pip show <packagename> ,也可以得到它的位置:

在此处输入图像描述

If it's in current used python environment, open Command Palette and choose Developer: Reload Window , the problem should go away:如果它在当前使用的 python 环境中,打开命令面板并选择Developer: Reload Window ,问题应该是 go 了:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Pyautogui 未导入“没有名为‘pyautogui’的模块” - Pyautogui not importing "No module named 'pyautogui' " ImportError: 使用 anaconda 安装后没有名为 pyautogui 的模块 - ImportError: No module named pyautogui after installing with anaconda 尽管在 mac 终端上使用 pip 命令安装它,但无法在 Python 上使用“请求”模块 - Can't use "Requests" module on Python despite installing it with pip command on mac terminal 安装成功后导入tensorflow时出错 - Error while importing tensorflow after installing successfully 粘性模块未正确安装 - gooey module not installing correctly 导入模块在终端中有效,但在 IDLE 中无效 - Importing module works in terminal but no in IDLE 在终端中成功导入模块,但在 VS Code 中没有 - Successfully import a module in terminal, but not in VS Code ModuleNotFoundError:尽管模块已成功安装,但没有名为“SpeechRecognition”的模块 - ModuleNotFoundError: No module named 'SpeechRecognition' despite module being successfully installed Python:成功安装模块,但无法通过导入使用 - Python: installing a module successfully but it is not available via import Python 模块海龟没有正确导入 - Python module turtle not importing correctly
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM