简体   繁体   English

Pylance 无法解决 Pyautogui

[英]Pyautogui could not be resolved by Pylance

I installed pyautogui module on python3 (only python ver. I have installed on my pc), but for some reason visual studio is not detecting it.我在 python3 上安装了 pyautogui 模块(只有 python 版本。我已经安装在我的电脑上),但由于某种原因,Visual Studio 没有检测到它。 I import it the following way: "import pyautogui"我通过以下方式导入它:“import pyautogui”

I tried reinstalling it etc, but nothing helped.我尝试重新安装它等,但没有任何帮助。

Solution 1解决方案 1

Check if there is no more python version.检查是否没有 python 版本。

  1. Press Ctrl + Shift + P to open a new command pallete.Ctrl + Shift + P打开一个新的命令调色板。

  2. Find Jupyter: Select Interpreter to start Jupyter server找到Jupyter:Select解释器启动Jupyter服务器

  3. Pick your python version.选择您的 python 版本。

Solution 2解决方案 2

If you are working with Visual Studio Code and import any library, you will face this error: "unresolved import" .如果您正在使用 Visual Studio Code 并导入任何库,您将面临以下错误: “未解决的导入” To resolve this error, In your workspace settings, you can set your Python path like the following.要解决此错误,在您的工作区设置中,您可以设置 Python 路径,如下所示。

  1. Press Ctrl + Shift + P to open a new command pallete.Ctrl + Shift + P打开一个新的命令调色板。
  2. Find Preferences: Open Workspace Settings (JSON)查找首选项:打开工作区设置 (JSON)
  3. Add code and edit path:添加代码和编辑路径:
{
   "python.defaultInterpreterPath": "/path/to/your/venv/bin/python",
}

It looks like the python environment which you have installed the pyautogui was not the python environment you have selected in the VSCode.看起来您安装了pyautogui的 python 环境不是您在 VSCode 中选择的 python 环境。

You can get where you have installed the pyautogui through pip show pyautogui .您可以通过pip show pyautogui获得安装pyautogui的位置。

You can click the python interpreter version on the bottom-left of the VSCode to switch your python interpreter or reinstall the pyautogui in the selected environment.您可以单击 VSCode 左下角的 python 解释器版本来切换您的 python 解释器或在所选环境中重新安装pyautogui

After you select the environment in the VSCode, you can open a new terminal in the VSCode through Ctrl+Shift+` .在 VSCode 中 select 环境后,您可以通过Ctrl+Shift+`在 VSCode 中打开一个新终端。 The Python extension will help you activate the environment in the terminal and the package will be installed into the selected python environment. Python 扩展将帮助您在终端中激活环境,package 将安装到选定的 python 环境中。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM