How to import pygame in visual studio code?

懵懂的女人 提交于 2021-02-08 23:32:26

问题


I use visual studio code for coding (python) and now I have to write a program with pygame for my project and I can't import pygame in visual studio code (I can import it with the python script, it just can't be imported in visual studio code).


回答1:


Here is the solution I tried:

From left bottom of your vs code you can find python environment, you can in the image I marked red:

after clicking in the red marked area you can see below option to select:

from the option select your desired one. Suppose first i was try selecting 2nd one but it was not working then i tried with the last one and it worked.




回答2:


  1. Open the terminal of Vscode.
  2. Type pip install pygame or pip3 install pygame.
  3. Import pygame and enjoy it.



回答3:


If it works in the console when you type 'python yourscript.py' but not in vs code, you should press ctrl+shift+p and use clic on Python select interpreter to switch to the right env. if it sstill doesn't work then install the package by running 'python -m pip install pygame'



来源:https://stackoverflow.com/questions/54376745/how-to-import-pygame-in-visual-studio-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!