Home > Back-end >  Python VSCode: Installed modules not recognised
Python VSCode: Installed modules not recognised

Time:08-25

I am writing a discord bot in Python using Gitpod (which has VSCode Browser as its editor). I have installed Pycord 2.0 in the workspace using pip (obviously) but VSCode doesn't seem to be recognising it. I also have the Python VSCode extension installed which adds a 'Run' to the editor when a python file is selected. It used to work just fine but since a month ago it stopped working and the 'Run Code' button is running some sort of Python installation where none of the modules I installed are there. It also doesn't show any code hints for the modules.

Does anyone know what might be wrong?

Thanks :)

~ R2509

CodePudding user response:

Many developers have multiple python versions installed, and multiple environments with the same python versions, but different libraries installed. Therefore, we need to specify which python compiler VSCode needs to use.

Check on the bottom right of your VSCode, there should be a number down there representing an installation of python.

Python version

Upon clicking on it, VSCode will open a window on the top part, allowing you to select which of the many pythons you have installed you want to use. Find the one where you installed your libraries, and you should be good to go.

CodePudding user response:

Method one:

  • Use pip show Pycord to see where you installed the package Pycord

    enter image description here

  • then choose that environment

Method Two:

  • Choose a python version you want to use ( Ctrl Shift P --> Python:Select Interpreter )

    enter image description here

  • Create a new terminal activation environment

    enter image description here

  • Install the package using pip install pycord in the new terminal

    enter image description here

As a suggestion:

you can use a virtual environment to better manage python versions and various packages.

# Create a virtual environment named .venv
python -m venv .venv

# Activate this virtual environment
.venv\scripts\activate
  • Related