简体   繁体   English

导入“pygame”无法解决 Pylance

[英]Import "pygame" could not be resolved Pylance

I did pip install pygame .我做了pip install pygame When I do pip list , it is installed but when I am trying to import it, it doesn't work.当我执行pip list时,它已安装,但当我尝试导入它时,它不起作用。

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.如果您有 python 的多个实例,则 pip 可能会将它们安装在 Python 下 2. 因此,命令确保您下载 Python 3。

Else refer to here .其他参考这里 It may be vs-code throwing a false error.可能是 vs-code 抛出了错误。

If you have selected the right python interpreter, you will need not add the site-packages folder to the Extra Paths .如果您选择了正确的 python 解释器,则无需将site-packages文件夹添加到Extra Paths

Have you tried to switch the python interpreter to the right one which you have installed the packages?您是否尝试将 python 解释器切换到已安装软件包的正确解释器? You can click the Status Bar on the bottom left of the VSCode to switch it.可以点击VSCode左下角的状态栏进行切换。 You can refer to the official docs for more details.您可以参考官方文档了解更多详情。

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. Python的源码存放在py_src目录下,但是在查找依赖时,vscode的pylance插件以当前打开的目录为搜索路径,自动添加了. / SRC directory to the search path. /src 目录到搜索路径。 Add "python.analysis.extraPaths": ["./py_src"] in the settings.json can solve this question在settings.json中添加"python.analysis.extraPaths": ["./py_src"]可以解决这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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