Python 3.6 windows 无法使用从 pip 安装的包

Python 3.6 windows cannot use packages installed from pip

我不能使用在 python 上使用 pip 安装的任何软件包,它说没有安装 x 这样的软件包,尽管在使用 help('modules') 列出软件包时它列出了已安装的软件包 x。 尝试使用的包:discord 错误信息:

Traceback (most recent call last): File "C:\Users\Bob Ross\Desktop\Twitch bot\discord.py", line 1, in <module> import discord File "C:\Users\Bob Ross\Desktop\Twitch bot\discord.py", line 2, in <module> from discord.ext.commands import Bot ModuleNotFoundError: No module named 'discord.ext'; 'discord' is not a package

代码:

import discord
from discord.ext.commands import Bot
my_bot = Bot(command_prefix="!")
@my_bot.event
async def on_read():
    print("Client logged in")
@my_bot.command()
async def hello(*args):
    return await my_bot.say("Hello, world!")
my_bot.run("{token omitted}")

我是运行windows10.

您需要将脚本重命名为 discord.py 以外的名称;这会阻止导入您想要的模块,因为您的模块已被导入。

还要确保目录中没有 C:\Users\Bob Ross\Desktop\Twitch bot\discord.pyc