Pygame problem plz

Hi everyone.
I’m new to python, and I was trying some codes that need pygame but after I’ve installed it this problem faced me!
any ideas how to fix this ?


if there is such a package named pygame, and it is not currently installed on your computer
(this goes for any other package), you will first have to install it via the DOS command prompt as:

pip install package_name

On your computer’s search GUI on the bottom, just type: DOS, and it should appear.

when I complete the procedure in dos it says: Requirement already satisfied: pygame in c:\program files\python38\lib\site-packages (2.5.2), but is it not working, it shows the same problem

Ok, what version of Python do you have? Can you try installing the latest version 3.12?

If that does not work, you can try adding the PATH of this directory to the path variable environment.

i’ve the latest version 3.12.1, and I don’t know how to do the method you gave me

Try this:

import sys

Does that directory appear on the list?

c:\program files\python38\lib\site-packages

By the way, you have Python 3.8 installed not v3.12.

Note that the package is installed under the v3.8 of Python on your computer. Uninstall v3.8. (and
any other versions). Then, re-install the pygame package so that it installs under the Python v3.12. Afterwards, you should not have an issue. It helps if you have only the latest version of Python at
any one time so that there are no search conflicts.

Hi !

From your screenshot it seems that a virtual environment was created for your PyCharm project. By default, when you click on the green start button, PyCharm uses this virtual environment to run your script.

Currently, pygame is installed at your user level, but not in the virtual environment. To install it in the venv, you have several options. PyCharm’s user interface allows you to manage installed packages interactively, or you could type something like venv\Scripts\python.exe -m pip install pygame in the command line.

See Install, uninstall, and upgrade packages | PyCharm Documentation for documentation on the interactive solution.

1 Like

I’ve deleted all versions and even pycharm and now I’m reinstalling them and I installed the pygame but this happened in cmd : WARNING: The scripts pip.exe, pip3.12.exe and pip3.exe are installed in ‘C:\Users\user\AppData\Roaming\Python\Python312\Scripts’ which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

I’ve removed everything and I’m trying again but this message faced me after i completed installing pygame on cmd
the message: WARNING: The scripts pip.exe, pip3.12.exe and pip3.exe are installed in ‘C:\Users\user\AppData\Roaming\Python\Python312\Scripts’ which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

This is an unrelated problem, your original issue was that pygame was not installed in the virtual environment used by PyCharm.

Check out this question for the PATH-related warning windows - The script is installed in directory, which is not PATH - Super User. You won’t need to solve this for running you script in a virtual environment though.

Again, try the pip install pygame. Which directory is it pointing to (i.e., which directory was it downloaded to)?

To add a path to the PATH environment variables

Make sure the PATH is properly defined.
You can check this by going to the Control Panel:

Control Panel → System and Security → System → About
Click on: Advanced system settings
Click: Environment Variables
Check that the ‘User variables’ are correct

If your desired path is not listed, click the ‘New…’ button and proceed to add the new path (the directory where the packages are installed).

thank you I’ve just solved the problem and it worked!

This is one of the most frequently asked questions here. Reference material: