VSCode Intellisense not Working for pygame

≡放荡痞女 提交于 2021-02-02 09:35:53

问题


While coding in pygame, I realised that VSCode was not showing up itellisense for quite some pygame modules, and instead showed those modules as variables. After some digging, I found out that if you do import pygame.display as display, the intellisense show up just fine. Is there anyway I can use intelliense without importing these modules like this?


回答1:


'Autocomplete and IntelliSense' was provided by Python Server. In vscode, basically you can choose 'Jedi' or 'Microsoft', and they are with different actions. Honestly, both of them are not well enough, if you take advantage of Pycharm, you will not come across this problem.

In 'Jedi':


'import pygame', 'import pygame.display', 'from pygame import *': display will be treated as a value, so they don't work.

'from pygame import display', 'from pygame import display as display': display will be treated as a variable, so they don't work.

'import pygame.display as display': display will be treated as a module, so it works.


'import pygame', 'import pygame.camera', 'import pygame.camera as camera', 'from pygame import camera', 'from pygame import camera as camera': camera will be treated as a module, so it works.

'from pygame import *': it doesn't work, because can't find module 'pygame' or 'camera'.


Why did it happen? This is because the 'display' module was provided through 'display.cp38-win32.pyd' file, it is a .pyd file. And the 'camera' was provided through 'camera.py' file, it is a python file.

In 'Microsoft':


'import pygame': display will be treated as a value, so it doesn't work.

'import pygame.display', 'import pygame.display as display', 'from pygame import display', 'from pygame import display as display', 'from pygame import *': display will be treated as a module, so they works.


'import pygame', 'from pygame import *': can't find camera module, so they don't work. 'import pygame.camera', 'import pygame.camera as camera', 'from pygame import camera', 'from pygame import camera as camera': can find camera module, so they works.
Why did it happen? you can refer to https://docs.python.org/zh-cn/3/tutorial/modules.html#importing-from-a-package for why 'from pygame import *' work difference between display and camera.

来源:https://stackoverflow.com/questions/62475015/vscode-intellisense-not-working-for-pygame

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