Modulenotfounderror no module named pygame ошибка

I have installed python 3.3.2 and pygame 1.9.2a0. Whenever I try to import pygame by typing: import pygame I get following error message : Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03...

I have installed python 3.3.2 and pygame 1.9.2a0. Whenever I try to import pygame by typing:

import pygame

I get following error message :

Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import pygame
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import pygame
ImportError: No module named 'pygame'
>>> 

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

timrau's user avatar

timrau

22.4k4 gold badges52 silver badges64 bronze badges

asked Aug 19, 2013 at 15:26

user2398618's user avatar

5

go to python/scripts folder, open a command window to this path, type the
following:

C:python34scripts> python -m pip install pygame

To test it, open python IDE and type

import pygame

print (pygame.ver)

It worked for me…

LoukasPap's user avatar

answered May 4, 2017 at 9:33

Srikar Madhavapeddy's user avatar

3

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.

  • Install Python, and remember the install location
  • Go here and download pygame-1.9.2a0-cp35-none-win32.whl
  • Move the downloaded .whl file to your python35/Scripts directory
  • Open a command prompt in the Scripts directory (ShiftRight click in the directory > Open a command window here)
  • Enter the command:

    pip3 install pygame-1.9.2a0-cp35-none-win32.whl

  • If you get an error in the last step, try:

    python -m pip install pygame-1.9.2a0-cp35-none-win32.whl

And that should do it. Tested as working on Windows 10 64bit.

answered Apr 11, 2016 at 16:02

charlie's user avatar

charliecharlie

8461 gold badge11 silver badges17 bronze badges

3

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/~gohlke/pythonlibs/#pygame

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.

answered May 1, 2014 at 23:27

aaron-coding's user avatar

aaron-codingaaron-coding

2,5211 gold badge22 silver badges31 bronze badges

5

  1. open the folder where your python is installed
  2. open scripts folder
  3. type cmd in the address bar. It opens a command prompt window in that location
  4. type pip install pygame and press enter
  5. it should download and install pygame module
  6. now run your code. It works fine :-)

answered Dec 28, 2017 at 5:42

NARENDER REDDY's user avatar

I had the same problem and discovered that Pygame doesn’t work for Python3 at least on the Mac OS, but I also have Tython2 installed in my computer as you probably do too, so when I use Pygame, I switch the path so that it uses python2 instead of python3. I use Sublime Text as my text editor so I just go to
Tools > Build Systems > New Build System and enter the following:

{
    "cmd": ["/usr/local/bin/python", "-u", "$file"],    
}

instead of

{
    "cmd": ["/usr/local/bin/python3", "-u", "$file"],   
}

in my case. And when I’m not using pygame, I simply change the path back so that I can use Python3.

General Failure's user avatar

answered Dec 26, 2016 at 6:34

Megan Chang's user avatar

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):

pip install pygame==2.0.0.dev20

or try to install a pre-release version by enabling the --pre option:

pip install pygame --pre

answered Oct 23, 2020 at 5:51

Rabbid76's user avatar

Rabbid76Rabbid76

196k25 gold badges121 silver badges164 bronze badges

Resolved !

Here is an example

C:UsersuserAppDataLocalProgramsPythonPython36-32Scripts>pip install pygame

John's user avatar

John

2,5034 gold badges18 silver badges33 bronze badges

answered Nov 29, 2019 at 16:43

diego lara's user avatar

try this in your command prompt:
python -m pip install pygame

Oscar Nguyen's user avatar

answered Feb 18, 2021 at 17:21

Ace Standard's user avatar

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.

http://www.lfd.uci.edu/~gohlke/pythonlibs/

answered Nov 14, 2014 at 2:20

TriGeo's user avatar

TriGeoTriGeo

351 silver badge6 bronze badges

1

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.

If you don’t really know if you are using a virtual environment or not, check with the other contributors of the project. Or maybe try to find a file with the name activate like this: find . -name activate.

answered May 31, 2017 at 8:08

user2089810's user avatar

  1. Install and download pygame .whl file.
  2. Move .whl file to your python35/Scripts
  3. Go to cmd
  4. Change directory to python scripts
  5. Type:

    pip install pygame
    

Here is an example:

C:UsersuserAppDataLocalProgramsPythonPython36-32Scripts>pip install pygame

Stephen Rauch's user avatar

Stephen Rauch

46.7k31 gold badges109 silver badges131 bronze badges

answered Dec 14, 2017 at 3:35

EDGE 074's user avatar

I just encountered the same problem and found that I am having multiple interpreters of the different versions installed in my system and pygame got installed in one of them when I installed it using command but in my IDE another interpreter was selected so this messed up my system, try to see if you are also having the same situation.

answered Jun 26, 2021 at 15:47

Tanishq chandra's user avatar

Just use this command in the terminal python3 -m pip install -U pygame --user

answered Sep 22, 2022 at 14:51

Eduardo-Puentes's user avatar

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).

answered Aug 18, 2014 at 21:58

KalELonRedKryptonite's user avatar

3

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.

answered Mar 6, 2018 at 12:34

Joe's user avatar

JoeJoe

8,0113 gold badges17 silver badges23 bronze badges

I ran into the error a few days ago! Thankfully, I found the answer.

You see, the problem is that pygame comes in a .whl (wheel) file/package. So, as a result, you have to pip install it.

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.

Step4. Click ‘Ok’.

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!!!

answered Aug 28, 2018 at 21:39

First execute python3 then type the command import pygame,now you can see the output

answered Apr 16, 2020 at 11:06

brean's user avatar

breanbrean

7572 gold badges9 silver badges17 bronze badges

For this you have to install pygame package from the cmd (on Windows) or from terminal (on mac). Just type pip install pygame
.If it doesn’t work for you, then try using this statement pip3 install pygame .
If it is still showing an error then you don’t have pip installed on your device and try installing pip first.

answered Aug 21, 2020 at 20:04

Ansh's user avatar

AnshAnsh

686 bronze badges

make sure if you are on windows that your library directory is added to path

answered Aug 14, 2021 at 9:21

dragon445's user avatar

dragon445dragon445

1211 silver badge4 bronze badges

This may happen when pygame didn’t installed, install the pygame first

pip
pip install pygame

if dont work update the PIP by goto python install folder and type

python -m pip install --upgrade pip

hope it work

answered Aug 26, 2021 at 12:24

Azka Hamidzan F.'s user avatar

Try this solution:
Type in to cmd (Windows):

C:Users'Your name'> pip install -U pygame

You should remove python -m, py -m, python3 -m before the pip
Also remove --user behind it.

It will said:

C:Usersviait>pip install -U pygame
Defaulting to user installation because normal site-packages is not writeable
Collecting pygame
  Downloading pygame-2.1.2-cp310-cp310-win_amd64.whl (8.4 MB)
     ---------------------------------------- 8.4/8.4 MB 1.7 MB/s eta 0:00:00
Installing collected packages: pygame
Successfully installed pygame-2.1.2

Then test it in your IDE or cmd:
(CMD example)

C:Usersviait>python
Python 3.10.3 (tags/v3.10.3:a342a49, Mar 16 2022, 13:07:40) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
pygame 2.1.2 (SDL 2.0.18, Python 3.10.3)
Hello from the pygame community. https://www.pygame.org/contribute.html

(IDE example)

import pygame

You can do this without any errors.

answered Apr 5, 2022 at 9:17

Oscar Nguyen's user avatar

You could use

pip install pygame

but if you use IDE like PyCharm, then you could just either install it from Python Packages or use right click at the package name then left click on Show Context Actions then left click on Install package pygame

(Personally, I recommended using Python Packages for the package installing because it has documentation with it)

answered Nov 26, 2022 at 10:42

Foryxled_Dev's user avatar

You gotta use Pycharm and install it in Terminal using pip install pygame and also after that enter Pycharm and hover on pygame in the «Import pygame» and in Pycharm it will tell you to download that and you can easily download it and enjoy your result

answered Jun 4, 2021 at 14:13

Mushfiqur Rahman's user avatar

I was having the same trouble and I did

pip install pygame

and that worked for me!

answered Nov 30, 2016 at 18:38

TheHyperCake's user avatar

Posted by Marta on October 4, 2021 Viewed 37238 times

Card image cap

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:

Traceback (most recent call last):
  File line 1, in <module>
    import random, pygame, sys
ModuleNotFoundError: No module named 'pygame'

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:

Output:

py==1.8.1
pyasn1==0.4.5
pygame==1.9.4
pygubu==0.9.8.6
pyparsing==2.4.7
pytest==5.4.1

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

Let’s say you check your installed libraries using pip freeze, and you noticed the library list doesn’t include the pygame library. What’s next? You need to install the module using pip. All you need to do is executing the command below:

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.

Modulenotfounderror: no module named 'pygame'

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:

Output:

/Library/Frameworks/Python.framework/Versions/3.7/bin/python3

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:

Output:

/Library/Frameworks/Python.framework/Versions/3.7/bin/pip

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!

More Interesting articles

Modulenotfounderror: no module named 'pygame'
python errors
return statement
dfs in python

A common error you may encounter when using Python is modulenotfounderror: no module named ‘pygame’. This error occurs when Python cannot detect the pygame library in your current environment, and Pygame does not come with the default Python installation. This tutorial goes through the exact steps to troubleshoot this error for the Windows, Mac and Linux operating systems.

ModuleNotFoundError: no module named ‘pygame’

What is ModuleNotFoundError?

The ModuleNotFoundError occurs when the module you want to use is not present in your Python environment. There are several causes of the modulenotfounderror:

The module’s name is incorrect, in which case you have to check the name of the module you tried to import. Let’s try to import the re module with a double e to see what happens:

import ree
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
1 import ree

ModuleNotFoundError: No module named 'ree'

To solve this error, ensure the module name is correct. Let’s look at the revised code:

import re

print(re.__version__)
2.2.1

You may want to import a local module file, but the module is not in the same directory. Let’s look at an example package with a script and a local module to import. Let’s look at the following steps to perform from your terminal:

mkdir example_package

cd example_package

mkdir folder_1

cd folder_1

vi module.py

Note that we use Vim to create the module.py file in this example. You can use your preferred file editor, such as Emacs or Atom. In module.py, we will import the re module and define a simple function that prints the re version:

import re

def print_re_version():

    print(re.__version__)

Close the module.py, then complete the following commands from your terminal:

cd ../

vi script.py

Inside script.py, we will try to import the module we created.

import module

if __name__ == '__main__':

    mod.print_re_version()

Let’s run python script.py from the terminal to see what happens:

Traceback (most recent call last):
  File "script.py", line 1, in <module>
    import module
ModuleNotFoundError: No module named 'module'

To solve this error, we need to point to the correct path to module.py, which is inside folder_1. Let’s look at the revised code:

import folder_1.module as mod

if __name__ == '__main__':

    mod.print_re_version()

When we run python script.py, we will get the following result:

2.2.1

Lastly, you can encounter the modulenotfounderror when you import a module that is not present in your Python environment.

What is pygame?

Pygame (stylized as pygame) is a set of Python modules for writing video games. It is highly portable and runs on every platform and operating system, and Pygame does not automatically come installed with Python. The simplest way to install pygame is to use the package manager for Python called pip. The following instructions to install pygame are for the major Python version 3.

How to install pygame on Windows Operating System

First, you need to download and install Python on your PC. Ensure you select the install launcher for all users and Add Python to PATH checkboxes. The latter ensures the interpreter is in the execution path. Pip is automatically on Windows for Python versions 2.7.9+ and 3.4+.

You can check your Python version with the following command:

python3 --version

You can install pip on Windows by downloading the installation package, opening the command line and launching the installer. You can install pip via the CMD prompt by running the following command.

python get-pip.py

You may need to run the command prompt as administrator. Check whether the installation has been successful by typing.

pip --version

To install pygame with pip, run the following command from the command prompt.

pip3 install pygame

How to install pygame on Mac Operating System

Open a terminal by pressing command (⌘) + Space Bar to open the Spotlight search. Type in terminal and press enter. To get pip, first ensure you have installed Python3. You can use the package manager Homebrew to do this. To install Homebrew, run the following command from your terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Follow the steps and prompts before the installation starts, then insert the Homebrew directory at the top of your PATH environment variable. You can do this by adding the following line at the bottom of your ~/.profile file:

export PATH="/usr/local/opt/python/libexec/bin:$PATH"

Alternatively, if you have OS X 10.12 (Sierra) or older, use:

export PATH=/usr/local/bin:/usr/local/sbin:$PATH

You can check that you have Python 3 installed on your system by running:

python3 --version
Python 3.8.8

Download pip by running the following curl command:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

The curl command allows you to specify a direct download link, and using the -o option sets the name of the downloaded file.

Install pip by running:

python3 get-pip.py

From the terminal, use pip3 to install pygame:

pip3 install pygame

How to install pygame on Linux Operating System

All major Linux distributions have Python installed by default. However, you will need to install pip. You can install pip from the terminal, but the installation instructions depend on the Linux distribution you are using. You will need root privileges to install pip. Open a terminal and use the commands relevant to your Linux distribution to install pip.

Installing pip for Ubuntu, Debian, and Linux Mint

sudo apt install python-pip3

Installing pip for CentOS 8 (and newer), Fedora, and Red Hat

sudo dnf install python-pip3

Installing pip for CentOS 6 and 7, and older versions of Red Hat

sudo yum install epel-release

sudo yum install python-pip3

Installing pip for Arch Linux and Manjaro

sudo pacman -S python-pip

Installing pip for OpenSUSE

sudo zypper python3-pip

Once you have installed pip, you can install pygame using:

pip3 install pygame

Check pygame Version

Once you have successfully installed pygame, you can use two methods to check the version of pygame. First, you can use pip show from your terminal.

pip show pygame
Name: pygame
Version: 2.1.2
Summary: Python Game Development

Second, within your python program, you can import pygame and then reference the __version__ attribute:

import pygame

print(pygame.__version__)
2.1.2

Installing pygame Using Anaconda

Anaconda is a distribution of Python and R for scientific computing and data science. You can install Anaconda by going to the installation instructions. Once you have installed Anaconda, you can install pygame using the following command:

conda install -c cogsci pygame

Summary

Congratulations on reading to the end of this tutorial. The modulenotfounderror occurs if you misspell the module name, incorrectly point to the module path or do not have the module installed in your Python environment. If you do not have the module installed in your Python environment, you can use pip to install the package. However, you must ensure you have pip installed on your system. You can also install Anaconda on your system and use the conda install command to install the pygame library.

For further reading on installing data science and machine learning libraries, you can go to the articles:

  • OpenCV: How to Solve Python ModuleNotFoundError: no module named ‘cv2’
  • Requests: How to Solve Python ModuleNotFoundError: no module named ‘requests’
  • Pandas: How to Solve Python ModuleNotFoundError: no module named ‘pandas’
  • Matplotlib: How to Solve Python ModuleNotFoundError: no module named ‘matplotlib’
  • Flask: How to Solve Python ModuleNotFoundError: no module named ‘flask’

Go to the online courses page on Python to learn more about Python for data science and machine learning.

Have fun and happy researching!

This article will tell you how to install the Python Pygame module correctly and how to fix the problems during the installation process.

1. Install Python Pygame Module Use The PIP Install Command.

  1. Open the terminal and run the command pip install pygame in it.
    $ pip install pygame
    Collecting pygame
      Downloading pygame-2.1.2-cp37-cp37m-macosx_10_9_x86_64.whl (8.9 MB)
         |████████████████████████████████| 8.9 MB 1.2 MB/s 
    Installing collected packages: pygame
    Successfully installed pygame-2.1.2
    
  2. Run the command pip show pygame to verify the module installation.
    $ pip show pygame
    Name: pygame
    Version: 2.1.2
    Summary: Python Game Development
    Home-page: https://www.pygame.org
    Author: A community project.
    Author-email: [email protected]
    License: LGPL
    Location: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
    Requires: 
    Required-by:

2. Install Python Pygame Module Use The Binary Installer File.

  1. Besides using the pip install command, we can also install it using the downloaded binary installer file.
  2. Go to the Pygame GitHub website to download the Pygame installer file that matches your OS and Python versions.
  3. Open a terminal and go to the Pygame installer downloaded directory.
  4. Run the command python -m pip install –user pygame-2.1.2-cp37-cp37m-macosx_10_9_x86_64.whl to install the Pygame from the installer file.
    $ python -m pip install --user pygame-2.1.2-cp37-cp37m-macosx_10_9_x86_64.whl
    Processing ./pygame-2.1.2-cp37-cp37m-macosx_10_9_x86_64.whl
    Installing collected packages: pygame
    Successfully installed pygame-2.1.2
    
  5. Run the command python -m pygame –version to verify the installed Pygame moduel version.
    $ python -m pygame --version
    pygame 2.1.2 (SDL 2.0.18, Python 3.7.3)
    Hello from the pygame community. https://www.pygame.org/contribute.html
    /Library/Frameworks/Python.framework/Versions/3.7/bin/python: No module named pygame.__main__; 'pygame' is a package and cannot be directly executed

3. How To Fix The ImportError: No module named ‘pygame’.

3.1 Question.

  1. I installed pygame 1.9.2 in Windows, and my python version is 3.5. But when I import the pygame module in the python source code, it shows the error ImportError: No module named ‘pygame’. How can I fix this error?
    >>> import pygame
    Traceback (most recent call last):
    File "<pyshell#0>", line 1, in <module>
    import pygame
    ImportError: No module named 'pygame'

3.2 Answer1.

  1. Below are the steps to install Pygame 1.9.2 on Python 3.5.1 for Windows, you can try it.
  2. After you successfully install Python 3.5, you should write down the Python 3.5 installed folder for later use.
  3. Download the wheel file pygame-1.9.2a0-cp35-none-win32.whl and save it to the folder python35/Scripts.
  4. Open a dos window and cd to the python35/Scripts folder, then run the below command.
    pip3 install pygame-1.9.2a0-cp35-none-win32.whl
  5. If you can not run the above command successfully, you can run the below command instead.
    python -m pip install pygame-1.9.2a0-cp35-none-win32.whl
  6. Now when you import the pygame module, the error should disappear.

3.3 Answer2.

  1. I also meet such an error, but the reason is different.
  2. I installed multiple Python versions on my Windows, and I installed pygame library successfully into one of my Python versions.
  3. But my IDE used python interpreter does not contain the pygame library, so when I import pygame in my IDE the error is shown.
  4. After I select the python interpreter that has installed pygame library, the error disappear.
  5. wish this can help you too.

3.4 Answer3.

  1. This error happened when you do not install pygame successfully.
  2. Or you may have multiple Python versions installed, and pygame is installed in one of the python versions, but you import pygame in another python version.
  3. So you should make sure the pygame library has been installed in your python env, you can run the below command to check it.
    (MyPythonEnv) C:Userszhaosong>pip show pygame
    Name: pygame
    Version: 2.1.2
    Summary: Python Game Development
    Home-page: https://www.pygame.org
    Author: A community project.
    Author-email: [email protected]
    License: LGPL
    Location: c:userszhaosonganaconda3envsmypythonenvlibsite-packages
    Requires:
    Required-by:

4. How To Fix ERROR: Command errored out with exit status 1:…EOFError: EOF when reading a line When Install Pygame Using PIP.

4.1 Question.

  1. I run the command pip install pygame on windows 10, but it throws the error with the message ERROR: Command errored out with exit status 1:…EOFError: EOF when reading a line. My python version is 3.9. Below is the detailed error message. How can I fix it?
    Collecting pygame
      Using cached pygame-1.9.6.tar.gz (3.2 MB)
        ERROR: Command errored out with exit status 1:
         command: 'c:usersjerryappdatalocalprogramspythonpython39python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\jerry\AppData\Local\Temp\pip-install-4b04m745\pygame\setup.py'"'"'; __file__='"'"'C:\Users\jerry\AppData\Local\Temp\pip-install-4b04m745\pygame\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:UsersjerryAppDataLocalTemppip-pip-egg-info-up4741kz'
             cwd: C:UsersjerryAppDataLocalTemppip-install-4b04m745pygame
        Complete output (17 lines):
    
    
        WARNING, No "Setup" File Exists, Running "buildconfig/config.py"
        Using WINDOWS configuration...
    
    
        Download prebuilts to "prebuilt_downloads" and copy to "./prebuilt-x64"? [Y/n]Traceback (most recent call last):
          File "<string>", line 1, in <module>
          File "C:UsersjerryAppDataLocalTemppip-install-4b04m745pygamesetup.py", line 194, in <module>
            buildconfig.config.main(AUTO_CONFIG)
          File "C:UsersjerryAppDataLocalTemppip-install-4b04m745pygamebuildconfigconfig.py", line 210, in main
            deps = CFG.main(**kwds)
          File "C:UsersjerryAppDataLocalTemppip-install-4b04m745pygamebuildconfigconfig_win.py", line 576, in main
            and download_win_prebuilt.ask(**download_kwargs):
          File "C:UsersjerryAppDataLocalTemppip-install-4b04m745pygamebuildconfigdownload_win_prebuilt.py", line 302, in ask
            reply = raw_input(
        EOFError: EOF when reading a line
        ----------------------------------------
    ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

4.2 Answer1.

  1. From the message you provide, we can see that you just install the Pygame version 1.9.6. And your python version is 3.9.
  2. But Pygame 1.9.6 does not support python 3.9 now. So you had better use python 3.8 instead.
  3. Or you can install Pygame 2.0 with the command pip install pygame==2.0.0, Pygame 2.0 support python 3.9.
  4. You can also download the Pygame wheel file from https://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame, it contains the wheel file pygame‑1.9.6‑cp39‑cp39‑win32.whl that meet your needs.

  • #1

Traceback (most recent call last):
File «C:UsersмаксимDocumentsпрограммы питон2_pygame_draw.py», line 2, in <module>
import pygame
ModuleNotFoundError: No module named ‘pygame.
Если надо то могу скинуть код который я добавил.

  • #3

написало что pip не является внутренней или внешней программой в cmd

  • #4

добавьте в path
или переустановите питон, поставив галочку ADD PATH

  • #5

добавьте в path
или переустановите питон, поставив галочку ADD PATH

WARNING: You are using pip version 20.2.3; however, version 22.0.3 is available.
You should consider upgrading via the ‘c:usersмаксимappdatalocalprogramspythonpython38python.exe -m pip install —upgrade pip’ command. Выдало после того как инсталлировался pygame

  • #6

добавьте в path
или переустановите питон, поставив галочку ADD PATH

Все решено, спасибо за ответ.

Понравилась статья? Поделить с друзьями:
  • Module set response error status
  • Module object is not callable python ошибка
  • Module object is not callable error
  • Module not found error python
  • Module not found error pygame