简体   繁体   English

尽管已安装,但无法将 pygame 导入 VScode

[英]Can`t import pygame to VScode despite having it installed

I'm using pip 21.2.4 and python 3.9.7我正在使用 pip 21.2.4 和 python 3.9.7

I'm pretty sure I have pip installed since if I run pip --version in the terminal it gives me pip 21.2.4 from C:\Users\rohaan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pip (python 3.9) I'm pretty sure I have pip installed since if I run pip --version in the terminal it gives me pip 21.2.4 from C:\Users\rohaan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pip (python 3.9)

If I run pip install pygame in the terminal I get Requirement already satisfied: pygame in c:\users\rohaan\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (2.0.1) If I run pip install pygame in the terminal I get Requirement already satisfied: pygame in c:\users\rohaan\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (2.0.1)

Despite the requirement being satisfied when I import pygame I get ModuleNotFoundError: No module named 'pygame'尽管在我import pygame时满足了要求,但我得到ModuleNotFoundError: No module named 'pygame'

Does anybody know how to fix this?有人知道如何解决这个问题吗?

It looks like you are not using the python interpreter which you have installed the pygame package.看起来您没有使用安装了pygame package 的 python 解释器。

You can execute this code to verify which python interpreter you are using:您可以执行此代码来验证您使用的是哪个 python 解释器:

import sys
print(sys.executable)

Then you can switch the python interpreter to which you have installed the packages or you need to activate the environment before you want to install the package in order to install the package to the right place.然后你可以切换你已经安装包的python解释器或者你需要激活环境才能安装package以便将package安装到正确的地方。

在此处输入图像描述

This means you have multiple versions of python installed on your device, one has the module and the other tries to run the file, go to the control panel and check it out.这意味着您的设备上安装了 python 的多个版本,一个有模块,另一个尝试运行文件 go 到控制面板并检查它。

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

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