[英]ModuleNotFoundError: No module named 'discord'
Trying to run my.py file from CMD, but it can't find the discord module尝试从 CMD 运行 my.py 文件,但找不到 discord 模块
>>File 'C:\Users\\****\Desktop\Discord_Bot\main.py', line 1, in module
>>import discord
>>ModuleNotFoundError: No module named 'discord'
Although, when I run:虽然,当我运行时:
>>python
>>import discord
It works as intended, any suggestions?它按预期工作,有什么建议吗?
Go into the terminal and use: pip uninstall discord.py
wait a few seconds so it can fully delete it, and then use pip install discord.py
.进入终端并使用:
pip uninstall discord.py
等待几秒钟以便它可以完全删除它,然后使用pip install discord.py
。 Should work应该工作
Maybe it's the Python version issue.可能是 Python 版本问题。
When I tried running in python3.8 I got the same error.当我尝试在 python3.8 中运行时,我遇到了同样的错误。 Switched over to 3.6 and it worked.
切换到 3.6 并且它起作用了。
I would use我会用
pip install discord
instead of installing discord.py.而不是安装discord.py。 Hope this works!
希望这有效!
check for python interpreter location in pycharm.检查pycharm中的python解释器位置。 Or install discord with sudo pip command
或者使用 sudo pip 命令安装 discord
sudo pip install discord.py
解决问题
I imagine that your venv in pycharm and your environment in the command prompt have different packages installed.我想你 pycharm 中的 venv 和命令提示符中的环境安装了不同的软件包。 If the error is the program not running at command prompt try opening a command prompt and running
pip install discord
(pip must be in your PATH) to install it to your main python directory.如果错误是程序未在命令提示符下运行,请尝试打开命令提示符并运行
pip install discord
(pip 必须在您的 PATH 中)以将其安装到您的主 python 目录。 You'll notice that in PyCharm if you open the terminal tab it says如果您打开终端选项卡,您会注意到在 PyCharm 中它说
(venv) C:\\Your\\File\\Structure
(venv) C:\\你的\\文件\\结构
with "(venv)" meaning a virtual environment is loaded here that can have packages installed to it without altering your main installation on your PC (usually located at C:\\Program Files\\Python 3.5).带有“(venv)”的意思是这里加载了一个虚拟环境,可以在不改变PC上的主要安装(通常位于C:\\Program Files\\Python 3.5)的情况下安装包。 In order to run scripts from the command line, however, you will need the package to be installed in your main python directory which
pip install discord
will accomplish.但是,为了从命令行运行脚本,您需要将软件包安装在
pip install discord
将完成的主 python 目录中。
Make sure your file name its diferent the module you're trying to import (discord.py in your case) If its not the case,you can try pip install discord --force-reinstall
.确保您的文件名与您尝试导入的模块不同(在您的情况下为 discord.py) 如果不是这种情况,您可以尝试
pip install discord --force-reinstall
。 It may solve your problem它可能会解决您的问题
So, I encountered the same issue.所以,我遇到了同样的问题。 I tried everything mentioned above but nothing worked.
我尝试了上面提到的所有内容,但没有任何效果。 It turns out that my filename was
discord.py
.原来我的文件名是
discord.py
。 This was the thing causing the real problem.这才是真正的问题所在。 So, you shall also check your filename.
所以,你还应该检查你的文件名。 I believe it implies to other packages as well.
我相信它也暗示了其他包。 So
所以
discord has changed its name to yeirne discord.abc has become try: import discord.abc
discord 已更名为 yeirne discord.abc 已变为 try:
import discord.abc
You can try install it manually.您可以尝试手动安装它。 If you have git, you can use:
如果你有 git,你可以使用:
git clone https://github.com/Rapptz/discord.py.git
Then, go into the directory and use:然后,go 进入目录并使用:
sudo python setup.py install
You can also check to see if the Python path is correct, or if your Python version is supported by Discord.py.您还可以查看 Python 路径是否正确,或者 Discord.py 是否支持您的 Python 版本。 Hope this helps!
希望这可以帮助!
Trying to run my .py file from CMD, but it can't find the discord module尝试从CMD运行我的.py文件,但找不到discord模块
>>File 'C:\Users\\****\Desktop\Discord_Bot\main.py', line 1, in module
>>import discord
>>ModuleNotFoundError: No module named 'discord'
Although, when I run:虽然,当我运行:
>>python
>>import discord
It works as intended, any suggestions?它按预期工作,有什么建议吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.