简体   繁体   English

导入“discord”无法解决错误

[英]Import "discord" could not be resolved error

I'm trying to make a discord bot, and I keep getting this error: Import "discord" could not be resolved Pylance(reportMissingImports)我正在尝试制作 discord 机器人,但我不断收到此错误: Import "discord" could not be resolved Pylance(reportMissingImports)

I used this to install the package: py -3 -m pip install -U discord.py我用它来安装 package: py -3 -m pip install -U discord.py

I am using the cmd on Visual Studio Code for this.为此,我在 Visual Studio Code 上使用 cmd。 Can anyone help?任何人都可以帮忙吗?

Try these steps:尝试以下步骤:

  1. Run VS Code as administrator > Navigate to your project path in the Terminal (CMD) in VS Code > Then Run the command py -3 -m pip install -U discord.py以管理员身份运行 VS Code > 在 VS Code 的终端(CMD)中导航到您的项目路径 > 然后运行命令py -3 -m pip install -U discord.py

  2. If Step 1 doesn't work, Open the Command Prompt as administrator from the Windows System (Not in VS Code) > Navigate to the project path & Run that same command.如果步骤 1 不起作用,请从 Windows 系统(不在 VS Code 中)以管理员身份打开命令提示符 > 导航到项目路径并运行相同的命令。

  • And then restart the VS Code and check!然后重新启动 VS Code 并检查!

Note: Make Sure you have installed the latest Python 3.x version注意:确保您已安装最新的Python 3.x版本

First, you should use the following command to install the discord package.首先,您应该使用以下命令安装discord package。

pip install discord

Secondly, maybe there are multiple python environments on your machine, please use Ctrl + Shift + P to open the command palette, then search and select Python:Select Interpreter , and select the correct interpreter. Secondly, maybe there are multiple python environments on your machine, please use Ctrl + Shift + P to open the command palette, then search and select Python:Select Interpreter , and select the correct interpreter.

在此处输入图像描述

在此处输入图像描述

There are two ways to be right here有两种方法可以在这里

  • Select the interpreter environment where you successfully installed the discord package earlier Select 之前成功安装discord package的解释器环境
  • Choose an interpreter environment you want to use, then create a new terminal to activate the environment, and install the discord package for your new environment.选择您要使用的解释器环境,然后创建一个新终端以激活环境,并为您的新环境安装discord package。

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

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