ModuleNotFoundError: No module named 'discord'

安稳与你 提交于 2021-01-28 11:40:48

问题


Trying to run my .py file from CMD, but it can't find the discord module

>>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?


回答1:


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. Should work




回答2:


Maybe it's the Python version issue.

When I tried running in python3.8 I got the same error. Switched over to 3.6 and it worked.




回答3:


check for python interpreter location in pycharm. Or install discord with sudo pip command




回答4:


sudo pip install discord.py solves the problem




回答5:


I imagine that your venv in pycharm and your environment in the command prompt have different packages installed. 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. You'll notice that in PyCharm if you open the terminal tab it says

(venv) C:\Your\File\Structure

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). 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.




回答6:


Make sure your file name its diferent the module you're trying to import (discord.py in your case)



来源:https://stackoverflow.com/questions/49886183/modulenotfounderror-no-module-named-discord

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!