no module named pygame что делать
ModuleNotFoundError: No module named ‘pygame’
ModuleNotFoundError: No module named ‘pygame’
when running my code. I’m using pycharm.
4 Answers 4
I would just like to add to what the first answer is saying: If you are using pycharm, it still won’t work until you go to file >> settings >> >> [your project name] >> python interpreter. You will see a list of packages there. If pygame is on it, then good, else, you must double click on the field where the packages are. It leads you to a little pop up box where you can type in things. If you type in pygame, you should be able to install the package.
I ran into the same error a few days ago! Thankfully, I found the answer.
Pip installing is a very tricky process, so please be careful. The steps are:-
Step1. Go to C:/Python (whatever version you are using)/Scripts. Scroll down. If you see a file named pip.exe, then that means that you are in the right folder. Copy the path.
Step2. In your computer, search for Environment Variables. You should see an option labeled ‘Edit the System Environment Variables’. Click on it.
Step3. There, you should see a dialogue box appear. Click ‘Environment Variables’. Click on ‘Path’. Then, click ‘New’. Paste the path that you copied earlier.
Step5. Shift + Right Click wherever your pygame is installed. Select ‘Open Command Window Here’ from the dropdown menu. Type in ‘pip install py’ then click tab and the full file name should fill in. Then, press Enter, and you’re ready to go! Now you shouldn’t get the error again.
ImportError: No module named ‘pygame’
I have installed python 3.3.2 and pygame 1.9.2a0. Whenever I try to import pygame by typing:
I get following error message :
I went through some of the questions related to this error but none of the solution helped. I have 64 bit machine with Win7 OS
22 Answers 22
go to python/scripts folder, open a command window to this path, type the following:
To test it, open python IDE and type
Here are instructions for users with the newer Python 3.5 (Google brought me here, I suspect other 3.5 users might end up here as well):
I just successfully installed Pygame 1.9.2a0-cp35 on Windows and it runs with Python 3.5.1.
pip3 install pygame-1.9.2a0-cp35-none-win32.whl
If you get an error in the last step, try:
And that should do it. Tested as working on Windows 10 64bit.
I was trying to figure this out for at least an hour. And you’re right the problem is that the installation files are all for 32 bit.
Luckily I found a link to the 64 pygame download! Here it is: http://www.lfd.uci.edu/
Just pick the corresponding version according to your python version and it should work like magic. The installation feature will bring you to a bright-blue screen as the installation (at this point you know that the installation is correct for you.
Then go into the Python IDLE and type «import pygame» and you should not get any more errors.
Props go to @yuvi who shared the link with StackOverflow.
Here is an example
The current PyGame release, 1.9.6 doesn’t support Python 3.9. I fyou don’t want to wait for PyGame 2.0, you have to use Python 3.8. Alternatively, you can install a developer version by explicitly specifying the version (2.0.0.dev20 is the latest release at the time of writing):
I was getting the same error. It is because your version of Pygame is not compatible with your version of Python or Pydev. Go to this link and get the proper version of Pygame for your current version of Python. Ctrl F to find it faster or click on the word python in blue. up at the top. While you instal Pygame it should find the Python path by itself. At least mind did any ways. I run Pygame through Eclipse with Python 3.4.
Since no answer stated this:
Make sure that, if you are using a virtual environment, you have activated it before trying to run the program.
Here is an example:
I am a quite newbie to python and I was having same issue. (windows x64 os) I have solved, doing below steps
You don’t need 64 bit Python on Win64 system, just install the 32bit versions of both Python and Pygame and they will work just fine (and there is a ton more modules for them anyways).
I’m using the PyCharm IDE. I could get Pygame to work with IDLE but not with PyCharm. This video helped me install Pygame through PyCharm.
(It seems that PyCharm only recognizes a package; if you use its GUI.)
However, there were a few slight differences for me; because I’m using Windows instead of a Mac.
My “preferences” menu is found in: File->Settings…
Then, in the next screen, I expanded my project menu, and clicked Project Interpreter. Then I clicked the green plus icon to the right to get to the Available Packages screen.
I ran into the error a few days ago! Thankfully, I found the answer.
Pip installing is a very tricky process, so please be careful. The steps are:-
Step1. Go to C:/Python (whatever version you are using)/Scripts. Scroll down. If you see a file named pip.exe, then that means that you are in the right folder. Copy the path.
Step2. In your computer, search for Environment Variables. You should see an option labeled ‘Edit the System Environment Variables’. Click on it.
Step3. There, you should see a dialogue box appear. Click ‘Environment Variables’. Click on ‘Path’. Then, click ‘New’. Paste the path that you copies earlier.
Step5. Shift + Right Click wherever your pygame is installed. Select ‘Open Command Window Here’ from the dropdown menu. Type in ‘pip install py’ then click tab and the full file name should fill in. Then, press Enter, and you’re ready to go! Now you shouldn’t get the error again.
How to Fix Modulenotfounderror: no module named ‘pygame’
Posted by Marta on October 4, 2021 Viewed 7083 times
I will show why you might encounter the error modulenotfounderror: no module named ‘pygame’ when you are creating a game using the python library pygame.
Hey there! In this article I will show you why you might encounter the error modulenotfounderror: no module named ‘pygame’ when you are creating a game using the python library pygame. You will also learn how to fix this error so you can continue working on your game.
The pygame module provides functionality to create a graphical display, work with graphics, and read from input devices, like mouse and keyboard, on multiple platforms.
This module is a third-party module; therefore, the Python installation doesn’t include it by default. As a result, you need to install it separately. It is quite simple to install; you can find how in one of the sections below. Without further to do, let’s get started!
How to check pygame is installed.
Probably you are facing the following situation. You wrote a small program using pygame, included all imports, installed python; however, when you execute the program, you see the error:
This error means that the pygame module is not installed. Another option is that you have several python versions installed on your machine. It could be installed in a different python installation(python SDK) and not installed in the python installation you are using to execute the game.
Therefore, the first thing to tackle this problem is finding out if the module is installed. Whether you are using Mac or Windows, you can check if a module is installed using the pip tool. Pip is the package manager that python uses to keep track of all libraries installed. To check the list of installed libraries, you can run the following:
After running the pip freeze command, you will see the list of all python libraries installed on your machine. Now you can double-check if the pygame library is installed.
How to install pygame on mac
How to Fix When working from an IDE
Another possible scenario. It could be that you installed the module from the terminal; however, when you execute the game from your IDE, such as PyCharm, you still get the error.
In case you are working on mac, one possible reason is that your IDE is set up to use python 2. Python 2 is installed on the Mac operating system by default.
As a result, if you installed python 3, you have two python installations(python SDKs) in your machine. And your IDE should be set up to use python3, which includes pip as the “module/package manager.” Or the python SDK where the module is installed. Let’s see how to do that.
In Pycharm, go to File->Project Structure and check the project SDK. The project SDK indicates the Python installation that pycharm uses to execute your python scripts.
If there is “No SDK” selected, make sure you coose python 3. If python3 is not available in the dropdown, click on “New …” and add the Python SDK( or installation), using the path where you have installed python earlier.
In other words, you need to make your IDE point to the same python SDK, where you have installed the module.
Where is your python SDK?
In case you don’t know or don’t remember where you installed python, no problem. Pretty simple to find out. You can check just by executing the following command from your terminal:
The above line indicates where python is installed on your machine. The Python SDK will access any module through the pip manager that is part of the SDK. As a result, you should make sure your python command and pip are in the same location/path, which means they are part of the same SDK
Where is pip installed?
You can find out where pip is installed using the which command as well. As I mentioned earlier, make sure python and pip are in the same location, meaning they belong to the same SDK. Check the pip location using the command below:
The above output means the pip command is installed in the location above, and it is part of the python version 3.7.
Conclusion
In conclusion, you will encounter the error Modulenotfounderror: no module named ‘pygame’ for two main reasons. One is that the module is not installed. The other reason is that you installed the module in a different python SDK to the one you are using to executing your game.
I hope you enjoy the article, and thank you so much for reading and supporting this blog. Happy Coding!
pygame error: «ImportError: No module named ‘pygame'»
This is my situation:
I tried importing pygame in both python 3.4.2 and python 3.6.3 using both pip and pip3 respectively.
In the python 3.4.2 shell:
Traceback (most recent call last) is:
File «», line 1, in
import pygame
ImportError: No module named ‘pygame’
In the python 3.6.3 shell:
Traceback (most recent call last):
File «», line 1, in
import pygame
File «C:\Users\aditya dand\AppData\Local\Programs\Python\Python36\lib\site-packages\pygame__init__.py», line 141, in from pygame.base import *
ModuleNotFoundError: No module named ‘pygame.base’
Those are the errors that occurred.
What can I do to solve this?
6 Answers 6
gohlke/pythonlibs/#pygame to find a Windows installer that matches the version of Python you’re running. The current version of pygame is : pygame-1.9.4-cp37-cp37m-win_amd64.whl
Move this file to the folder C:\Users\username\AppData\Local\Programs\Python\Python37\Scripts
open cmd and then type:
and then type the command:
Now you have successfully installed pygame package.
open PyCharm File >> setting make sure the «Project Interpreter» has the «pygame» package like the following:
check if you have added python to path
ans done if any one need help delete all python version from system and install python 3.5.2 from https://www.python.org/downloads/release/python-352/
and search pygame and download pygame‑1.9.3‑cp35‑cp35m‑win_amd64.whl
then go to C:\Users\»your username»\AppData\Local\Programs\Python\Python35\Scripts> in this location in cmd ( command prompt )
type this line and done » pip3 install pygame-1.9.3-cp35-cp35m-win_amd64.whl «
hope this help you
If you are using Windows i had the same problem and i know how to fix it, follow the steps:
This will open the appdata roming file
Look at the bit at the top that says Appdata > roaming and click on app data
Pls comment if this doesnt make sense or you would like further details
Pygame «No module called pygame.base»
When I download pygame-1.9.2b8-cp36-cp36m-win32.whl from http://www.lfd.uci.edu/
gohlke/pythonlibs/#pygame I turn it into zip, take the headers in the pygame-1.9.2b8.data folder into pygame34/include/pygame and I put the other pygame file from the zip in the site-packages folder together with pygame-1.9.2b8.data as any tutorial shows, I always get this error:
EDIT: I use python 3.4.5, I have tried both python and pygame 64 and 32 bit but i still get this error
5 Answers 5
This error bugged me for months, what i did was:
Uninstalled the package
pip3 uninstall pygame
Purged the pip cache
Finally. Reinstalled pygame using pip3
pip3 install pygame
Worked like a charm 🙂
You probably have python installed for 32-bit. Uninstall and the install the 64-bit version. After that,
try usin pip3 install pygames to install pygames
Use pip3 tool to reinstall the pygame python module:
SUBLIME TEXT SOLUTION
OBS: THE REASON MOST GUI FRAMEWORKS DO NOT WORK ON SUBLIME IS BECAUSE OF THIS ONE LITTLE DETAIL HERE
Create a new build system:
DELETE EVERYTHING CONTAINED IN THIS NEW FILE AND ADD THIS PIECE OF CODE:
ATTENTION: DO NOT CHANGE THE CURRENT DIRECTORY YOU ARE ON, WHICH IS THE
P.S I Saved mine as 3.7 but it works the same, as long as the code inside the file is 3.8, or whatever version you have on your machine currently.