为什么我的 Python 代码看不到导入的 discord.py 模块?

Why doesn't my Python code see the imported discord.py module?

我正在尝试使用 Python 制作我的第一个 Discord Bot,它在我的桌面 Windows 计算机上运行完美。我还有一台笔记本电脑 运行 Ubuntu,我将存储库克隆到 Intellij 中,但无法正常工作。因为我使用的 Python 版本略有不同(3.6.1 与 3.5.2),所以我将其设置为忽略我的 misc.xml 文件,因为它包含一个项目-JDK-名称。我根据另一个项目 (3.5.2) 自动生成的文件在我的笔记本电脑上手动重新创建了它。

在笔记本电脑上,它在 import discord 行下划线并告诉我找不到模块。我使用 python3 -m pip install discord 安装了它,重新安装时告诉我它已经存在。

基于此 link,我还尝试了 运行 python3 然后 import discord 在 cmd 中,但没有输出,所以我假设它没有有一个错误。那么,为什么我的 Python 项目看不到该模块?

您的 ide 可能一直在使用与您下载 discord.py 的解释器不同的 python 解释器。您将需要更改 SDK 设置。按照本教程进行操作:https://www.jetbrains.com/help/idea/2017.1/configuring-python-interpreter-for-a-project.html

To configure Python interpreter for a Python module, follow these steps

Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).

In the Project Structure dialog box, click Modules node under the Project Settings.

In the Module pane of the selected Python module, click the Dependencies tab.

Click Module SDK drop-down list, and select the desired Python interpreter from the list of the previously configured available Python interpreters.

If the interpreter you need is missing in the list of available interpreters, click New next to the Module SDK field, choose Python SDK from the pop-up menu, choose interpreter type (local, remote, etc.) and then select the desired executable.