Importerror: No Module Named 'Pygame'

Pygame is installed yet i there is a 'Import Error: No module named 'pygame'

The problem might be that VSCode is running your code with python not python3 so you will have to install it with pip install pygame or run it from the console by typing python3 mycode.py

No module named pygame on a python to exe file

pip install pygame is the command you are looking for.

Run this command in your terminal and then try again.

ImportError: No module named 'pygame' on Ubuntu

Three ways to check this:

1. Using apt-cache to search and apt-get to install :

apt-cache search pygame

Result:

python-pygame - SDL bindings for games development in Python

Then install:

sudo apt-get install python-pygame

2. Using pip:

pip install Pygame

3. Manual installation:

  • Download the source from Pypi;
  • Extract the .tar.gz file, and install using:

    python setup.py install

obs: check the python version you want to install, if you use Python3, use:

pip3 install Pygame

Running python file from command prompt ModuleNotFoundError: No module named 'pygame'

You're trying to execute the script with global python which doesn't have the pygame package installed. So, you have to activate the virtual environment first. To do this, go to venv/Scripts/ and there will be an "activate" file that you need to execute. Once you have done this you can run your script and it should work.

More info on: https://docs.python.org/3/tutorial/venv.html



Related Topics



Leave a reply



Submit