0

In my code I have:

'''import pygame'''

When I run:

ModuleNotFoundError: No module named 'pygame'

When I pip install pygame (also tried pip3 install pygame and pip3.7 install pygame):

Requirement already satisfied: pygame in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (2.0.1)

Really lost here any help appreciated.

python --version = Python 3.7.4

pip --version =

pip 21.2.4 from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)

Nerfed
  • 27
  • 1
  • 6
  • 1
    What command are you using to run your script? Use `python -m pip install pygame` to ensure you run pip for the same python install as the `python` command – Iain Shelvington Sep 14 '21 at 03:03
  • Requirement already satisfied: pygame in /opt/anaconda3/lib/python3.7/site-packages (2.0.0.dev6) Okay so doing this it says pygame is in anaconda, but if you look above it says it is just in my python3.7 lib? – Nerfed Sep 14 '21 at 03:14
  • 1
    And what command is being used to run the script? – Iain Shelvington Sep 14 '21 at 03:17
  • So it worked when I open my terminal and cd into the file and do python filename.py but when I am in VSCode and click "Run Python File in terminal" it gives this error. – Nerfed Sep 14 '21 at 03:22
  • 3
    VSCode may be using a different python installation, see [this answer](https://stackoverflow.com/a/62922929/2280890) for instructions on how to configure VSCode correctly. – import random Sep 14 '21 at 03:24
  • ^ This worked. Thanks I had to change my python from 3.7.6 to 3.7.3 in VS code... – Nerfed Sep 14 '21 at 03:27

1 Answers1

1

While getting such error even after installing the required module, check for the following:

The python environment/ installation used by your IDE should be same as the environment where the module is installed.

Else, change the environment to the Python environment paste the path to python.exe inside bin folder of your environment

And install the package again.

Specific for VS Code Click on python followed by version number or venvin the bottom ribbon of the editor and add the path to interpreter or choose an existing interpreter you want to use.