简体   繁体   中英

Python VSCode: Installed modules not recognised

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.

I have tried pip show py-cord and changing the selected VSCode python interpreter accordingly. I've also tried changing th interpreter and installing Pycord into that interpreter but none of that worked. I am running Gitpod on an iPad 6 (model A1893, iPadOS 15.6.1) in Safari

Does anyone know what might be wrong?

Thanks:)

~ R2509

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.

蟒蛇版本

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.

Method one:

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

    在此处输入图像描述

  • then choose that environment

Method Two:

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

    在此处输入图像描述

  • Create a new terminal activation environment

    在此处输入图像描述

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

    在此处输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM