Import "discord" could not be resolved error - python

I'm trying to make a discord bot, and I keep getting this error:
Import "discord" could not be resolved Pylance(reportMissingImports)
I used this to install the package:
py -3 -m pip install -U discord.py
I am using the cmd on Visual Studio Code for this. Can anyone help?

Try these steps:
Run VS Code as administrator > Navigate to your project path in the Terminal (CMD) in VS Code > Then Run the command py -3 -m pip install -U discord.py
If Step 1 doesn't work, Open the Command Prompt as administrator from the Windows System (Not in VS Code) > Navigate to the project path & Run that same command.
And then restart the VS Code and check!
Note: Make Sure you have installed the latest Python 3.x version

First, you should use the following command to install the discord package.
pip install discord
Secondly, maybe there are multiple python environments on your machine, please use Ctrl+Shift+P to open the command palette, then search and select Python:Select Interpreter, and select the correct interpreter.
There are two ways to be right here
Select the interpreter environment where you successfully installed the discord package earlier
Choose an interpreter environment you want to use, then create a new terminal to activate the environment, and install the discord package for your new environment.

Related

"Import "youtube_dl" could not be resolved" Using virtual environment / pip, all other imports work

screenShot of vsc
A screenshot of my visual studio code is above in the link ^.
I have a virtual env running in the terminal in vsc. I have the vsc python interpreter set to python 3.10.7. I have been using pip to install dependencies. All other dependencies work, ie flask, tensorflow, numpy, etc. But youtube_dl says it cannot be resolved. It is installed in the location shown: c:\users\user\onedrive\desktop\projectName\.venv\lib\site-packages
Any idea why this is not resolving?
I have tried doing pip install youtube_dl within the virtual env. I have tried it without of the virtual env, I have tried using python3 -m pip install youtube_dl. Not sure why this won't resolve.
Please note that Python 3.10.7 in the lower right corner is not consistent with the python version you understand.
It is Python Interpreter instead of python version.
This problem is caused by the wrong python interpreter. You installed the package in the .venv environment and run the file at the base environment.
The solution is using shorcuts "Ctrl+Shift+P" and typing "Python: Select Interpreter" to choose your .venv environment. (You can also click Python 3.10.7 in the lower right corner).
You Can click on the "3.10.7 64-bit" and vscode will show you selected python environment and then make sure that the chose env is your '.venv'.
You can also run you code on terminal with activated .venv and there should not be a Problem.

Python was not found after closing commandline. Windows opens app store when I type python

I have downloaded and installed python from here.
Then I restarted and opened a commandline and typed
python --version
I recorded all my actions, so I can post a screenshot of that:
It works and shows the version number.
Then I performed the following steps to install Jupyter because I want to use a local runtime with Google Colab:
In the Windows commandline (not in the Python window!!), I type this:
pip install virtualenv
python -m pip install --upgrade pip
virtualenv opencv (I guess I can choose a random name here because we will not be using OpenCV, right? But for simplicity, I keep this name now)
I CD to c:\users\MYUSERNAME\opencv\Scripts
activate.bat
pip install numpy
python -m pip install jupyter
Now my browser opens this page: http://localhost:8888/tree
Now I click "New" and "Python 3 (ipykernel)"
Now I want to install the extension jupyter_http_over_ws.
I type:
pip install jupyter_http_over_ws
Nothing shows up when I type text on the keyboard. It looks like this:
Because I want to be able to type again, I close the command line and open it again.
Now I type again:
pip install jupyter_over_http_ws
It says
The command "pip" has been misspelt oder was not found.
Because I have no idea what is happening, I type:
python --version
I am expecting that it shows the version number like before.
But instead it shows
"Python was not found."
Why is that?
ps: When I type "python", it starts the Microsoft App Store and offers me to download it:
Thank you!
What happens if you add your python installation path to the environment variables?
https://www.educative.io/answers/how-to-add-python-to-path-variable-in-windows
Don't forget to restart Windows after adding the path!

Discord.py not being detected in vscode

I had installed discord.py in cmd like so, pip install discord.py, but whenever I type import discord in vscode, It doesnt seem to detect it and gives the error "Import "discord" could not be resolved". I also made a new terminal in vscode and typed in pip install discord.py, and it said that all requirements were fulfilled! How can I import and use discord in vscode??
Please install the required modules in the currently selected environment:
(You could use the shortcut key Ctrl+Shift+` to open a new VSCode terminal, it will automatically enter the current Python environment)
Please check the source of the installation tool pip, the module is installed here:
Run:
check:
Reference: discord.py and environment in VSCode.

discord py in Visual Studio Code not detecting extension

I installed discord.py with the voice and without in the visual studio code terminal because in my cmd it doesn't detect pip like a command (I'm on windows). I've tried too in the python terminal but it doesnt detetect pip like a command.
Please help.
Pip is installed, it's just not installed as a command, and that's on purpose. What you want to do is create a virtual environment and then install into there by activating the environment and then using python -m pip.

VSCode: There is no Pip installer available in the selected environment

I'm trying to run the autopep8 linter on a Python file in VSCode.
I've followed the instructions here: https://code.visualstudio.com/docs/python/environments and selected my interpreter (⇧⌘P): /usr/local/bin/python
I then try to format my code, and VSCode says autopep8 isn't installed, and can be installed via Pip. However, when I try to install via Pip, it says There is no Pip installer available in the selected environment.
I then tried launching a terminal in the current environment by selecting Python: Create Terminal from the Command Palette.
The terminal opens fine, pip is present, and I'm even able to pip install autopep8 in the terminal that opened in VSCode, but when I try running the Format Document command I get the same errors that autopep8 and pip aren't available in the environment.
On Ubuntu16.04, I worked with Python3 in vscode and
apt-get install python3-pip
solves my problem.
That's because I discover that: Under my terminal, I type the pip -V. It displays it's for Python2, not for Python3.
Man you can only change the interpreter.
Go in (ctrl + shift + p), then type Python: Select Interpreter, this way you choose the version that your extension needs.
This worked for me.
I have multiple python versions:
2.7
3.6
3.7
Tell the vscode/ visual studio code, which version to use:
press the following (Show All Commands): Ctrl + Shift + P
paste the following: Python: Select Interpreter
Select one of the version that it shows, I have selected python 3.7.3 64-bit
Update python path in settings:
press Ctrl + , to open Settings
search for python.pythonPath
change python to /usr/bin/python3.7
Note: this may not be needed, however, make sure /usr/bin/python3.7 really exists for you, you may have at a different path like /usr/local/bin/python3.7, etc.
I had pip but it was 2.7, but since I am choosing python 3, it's pip needs to be installed
Run the following command in Terminal: apt-get install python3-pip
Restart vscode
With the above steps, all issues got resolved. Hope that helps.
try Ctrl+Shift+P
then type
Python: Select Interpreter
and select the python version.
Installing python3-pip fixed the issue for me.
apt-get install python3-pip
1.Select the File > Preferences > Settings command (⌘,) to open your User Settings.
2.Search and Create or modify an entry for python.pythonPath with the full path to the Python executable according to your requirements.For Example i changed it to python2.6 path to this path /usr/local/bin/python3.
I had the same problem today, none of the solutions helped me. Eventually, I figured it out myself.
I'm posting this answer for people who are having this problem. Just go to your ./venv folder and you will find a .cfg file.
Just make sure include-system-site-packages is set to true
home = /usr/bin
include-system-site-packages = true
version = 3.8.5
If it still doesn't work, just run sudo install python3-pip once in the terminal. Of course you could always change the version here as well.
(on mac)if you are using python3 but vscode told you pip was not installed , you could change python version on vscode bottom.
And I guess you are using another terminal but not bash , vscode's default terminal is bash. Bash don't know you have install pip#2.
For WSL users:
If you have your work files in linux subsystem path, you still need pip for windows in order to VSCode to use it.
On Ubuntu:
Make sure, that you have Python and pip installed.
Go to Settings, type python.py in search input. This should find Python Path settings.
Remove this path (if it is currently setted), save. Exit Code and set this to current value.
For me is /usr/bin/python3
Had this issue when trying use autopep8. For me - it had nothing to do with pip (I know it is installed) but the path the VScode python extension was using.
If you open up the extension and go to it's setting and scroll down, there is a path you can designate for autopep8: Python › Formatting: Autopep8 Path
I used the path recommended by these docs:
https://code.visualstudio.com/docs/python/editing#_formatting
Which was: python.formatting.autopep8Args
I stopped getting the error.
For Windows system check the environment variable>System variables
check the Path variable for the python path.(if not found set the path variable for python)
Copy the path and paste under vscode>file>preferences>settings>python.pythonPath
It worked for me.
I ran into this problem while learning django and the terminal would not let me pip install anything.
Create a virtual environment in shell and then use the path of the environment as your interpreter. This worked for me.
Note: You might want to create to create the environment in a different shell altogether and then upload the folder of the environment into vscode.
Then you open up the settings file in the environment folder.
This image will hopefully give you a good idea. Click Here
I was having a similar problem with pylint in a docker container. I realized that the reason the VS-Code-prompted pylint install didn't work for me was because I was using the global python installation (global inside my docker container, anyway), which can require elevated permissions to install things and VS code wasn't running as root in the container. According to the vs code python extension docs:
Note: If you're using a global environment and VS Code is not running elevated, linter installation may fail. In that case, either run VS Code elevated, or manually run the Python package manager to install the linter at an elevated command prompt for the same environment: for example sudo pip3 install pylint (macOS/Linux) or pip install pylint (Windows, at an elevated prompt)
Go in (ctrl + shift + p), then type Python: Select Interpreter,
then type Python: Select Interpreter and then click on "Enter interpreter path"
Then click on "Find.. Browse your file. "
Then type Python in c drive search bar and click on latest version of python in case if you have multiple version of python. Enter and modify wait for sometimes to complete then close.
After that restart your vs code.
It worked for me it will work for you also.
Note: This is a solution for Windows.
First make Sure your Python is installed properly. Run the following command:
py --version
If the Previous command is running fine it will give you your python version. In that case go ahead and check if pip is present or not. Run the below command to check:
py -m pip
If pip is present in your system it show give you a list of option and info. If that's the case then go Ahead and run pip. All you need to do is precede the command you would normally write with py -m. For example:
pip install flask
py -m pip install flask
This should solve your problem.

Categories

Resources