3

I did pip install pygame. When I do pip list, it is installed but when I am trying to import it, it doesn't work.

Freddy Mcloughlan
  • 4,129
  • 1
  • 13
  • 29

4 Answers4

1

Try:

python3 -m pip install pygame

If you have multiple instances of python, pip may install them under Python 2. Hence the command to ensure you download for Python 3.

Else refer to here. It may be vs-code throwing a false error.

Freddy Mcloughlan
  • 4,129
  • 1
  • 13
  • 29
1

If you have selected the right python interpreter, you will need not add the site-packages folder to the Extra Paths.

Have you tried to switch the python interpreter to the right one which you have installed the packages? You can click the Status Bar on the bottom left of the VSCode to switch it. You can refer to the official docs for more details.

Steven-MSFT
  • 7,438
  • 1
  • 5
  • 13
0

The source code of Python is stored in py_ SRC directory, but when looking for dependencies, the pylance plug-in of vscode takes the currently open directory as the search path, and automatically adds the. / SRC directory to the search path. Add "python.analysis.extraPaths": ["./py_src"] in the settings.json can solve this question

zirconium
  • 1
  • 2
0

I know this is old but I just wanted to say this for anyone else finding this with the same issue I had. There was something at the bottom left of vscode called restricted mode when I clicked it and then clicked trust it seemed to work.