我无法使用在 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}")
我运行的是 Windows 10。
最佳答案
您需要将脚本重命名为 discord.py
以外的名称;这会阻止导入您想要的模块,因为您的模块已被导入。
还要确保目录中不存在 C:\Users\Bob Ross\Desktop\Twitch bot\discord.pyc
。
关于Python 3.6 windows 无法使用从 pip 安装的包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42894043/