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.

- 4,129
- 1
- 13
- 29

- 41
- 1
- 1
- 2
-
Are you sure you are using the correct syntax for importing? Otherwise, it looks like this problem: https://stackoverflow.com/questions/18317521/importerror-no-module-named-pygame – danyroza Aug 15 '21 at 10:33
-
After you `pip install pygame` restart vs code . This might work. – Tanish Sarmah Aug 15 '21 at 11:35
-
1It solved. Add site-packages folder to Python > Analysis: Extra Paths – Yakup Mete Mağden Aug 15 '21 at 11:52
-
On the bottom left of VSCode, you can choose the interpreter where you install pygame. Make sure you install the correct one – Ardiya Aug 15 '21 at 15:44
4 Answers
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.

- 4,129
- 1
- 13
- 29
-
Thanks. Your page worked. Problem solved when I add item to my site-packages at Python > Analysis: Extra Paths – Yakup Mete Mağden Aug 15 '21 at 11:49
-
1`pip3` may not be available on the OS, so `python3 -m pip` would be recommended – OneCricketeer Aug 15 '21 at 13:07
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.

- 7,438
- 1
- 5
- 13
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

- 1
- 2
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.