I had the same issue. The solution is to change the Python Interpreter. You can do it by Ctrl+Shift+P and choose "Python: Select Interpreter" in visual studio code.
Answer from KKK on Stack Overflowpython - i have download discord package but its not working in vscode - Stack Overflow
python - Discord.py not being detected in vscode - Stack Overflow
Discord Bot Problems
python 3.x - Pip install discord not working in Vs code - Stack Overflow
Videos
I had the same issue. The solution is to change the Python Interpreter. You can do it by Ctrl+Shift+P and choose "Python: Select Interpreter" in visual studio code.
I was having a lot of troubles with stuff I got with pip install and they were installed successfully, but when I tried to import them, they didn't import
I found out that for me, some of the installs get installed to a separate folder, and not the correct folder that they need to be in to import.
If you try installing it again with pip install, then it will say you already have it installed and it will give you the location where the file is, and I copied the files from there and pasted them into the correct location which is (on windows)
C:\Users{Username}\AppData\Local\Programs\Python{Python Version}\Lib\site-packages
I was trying to find a place to share this and this was the closest to the issue, so I hope it helps!
Hello! I've been having problems recently with VS Code. I've been trying to make a discord bot for my discord server and I don't know if it's a VS Code problem or maybe the terminal downloaded the files wrong. This is the code i have typed out:
import Discord
import random
Token = "yourtokenhere"
client = Discord.Client()
*client.event
async def on_ready():
print("We have logged in as (0.user)".format(client))
client.run(Token)
The * is supposed to be an At sign but reddit seems to hate At signs.
When I run the code I get this message:
line 1: 'Import discord'
ModuleNotFoundError: no module named 'discord'
I have already downloaded discord.py into VS code. Also Discord on line 1 has a red line under it. if I hover over it with my mouse you get this: Import "Discord" could not be resolved Pylance(reportMissingImports)
I'm trying to use torch in a python script but even though it's pip installed, pylance doesn't recognize it
https://imgur.com/EM5fEIo
Any advice on how to resolve this? Thanks.
Once again my excitement has turned to frustration doing what probably is very fcking simple.
I thought it looked like a fun project to make a discord bot.
I make a new directory, create a virtual environment, activate the virtual environment, install the packages. Should be good yeah?
.env is present in the main directory complete with the discord token.
-
I open VScode I even activate the virtual environment in the VSCode terminal.
-
When I get to the part where I
import discord&from dotenv import load_dotenvit will not work. -
VSCode claims that
'Import "discord" could not be resolved'
Both packages definitely installed successfully and can be found in the .venv/Lib/site-packages
This is the same method I would use to set up a django project which is something I have a little more experience with.
Can anyone tell me where I've gone wrong or explain what is happening so I can avoid it next time?
Thanks.
edit: I should also mention that I'm 99.99% it's not a typo, I've tried typing it out myself and copying it straight from the GitHub repo that was provided with the tutorial.
How are you running the code? Did you double-check the active interpreter (bottom line of the VS Code window) is your virtual environment?
If you only activated it in the terminal, VS Code's plugins will default to the main installation and therefore won't see the packages you installed in the virtual environment. It'll run fine if you run from the terminal, but not with the green arrow icon.
This stackoverflow thread has a couple of approaches to solve this issue, have you tried them?
Link: https://stackoverflow.com/questions/61052890/import-could-not-be-resolved-reported-by-pyright