84

I'm trying to install Pygame. I am running Windows 7 with Enthought Python Distribution. I successfully installed pip, but when I try to install Pygame using pip, I get the following error:

"Could not install requirement Pygame because of HTTP error HTTP error 400: Bad request for URL ..."

I can't find anything about this issue with a Google search, but I did find another Stack Overflow question that prompted the asker to use the following command:

pip install hg+http://bitbucket.org/pygame/pygame

This gave me the following error:

Cannot find command hg

I'm not sure what else to do, as everything I find with a Google search is for Mac, so I don't know how well I can follow those instructions on Windows.

jchanger
  • 739
  • 10
  • 29
NumberOneRobot
  • 1,691
  • 6
  • 17
  • 23
  • 2
    If I remove the "hg" portion of the install command, I get the following error: "Cannot determine archive format of c:\users\...\appdata\local\temp\pip-tnjf7m-build" – NumberOneRobot Jul 25 '13 at 21:36
  • 2
    why dont you just download it from the pygame site – Serial Jul 25 '13 at 23:31
  • 2
    How do I install it once I download it? – NumberOneRobot Jul 26 '13 at 00:10
  • 3
    its a .msi so i belive it auto installs http://www.pygame.org/download.shtml – Serial Jul 26 '13 at 00:13
  • 3
    There is `mercurial` for Windows, it seems - have you tried it? http://mercurial.selenic.com/wiki/WindowsInstall `hg` is the main mercurial command. – moon.musick Aug 26 '13 at 17:59
  • Given that mercurial is a python application, you can also install it with `pip install mercurial`. This is handy if you want to put all of your build dependencies into one `requirements.txt` file to be installed with pip. – GDorn Dec 18 '14 at 02:15

28 Answers28

102

Steps to install PyGame using pip

  1. Install build dependencies (on linux):

    sudo apt-get build-dep python-pygame
    
  2. Install mercurial to use hg (on linux):

    sudo apt-get install mercurial
    

    On Windows you can use the installer: Download

  3. Use pip to install PyGame:

    pip install hg+http://bitbucket.org/pygame/pygame
    

    If the above gives freetype-config: not found error (on Linux), then try sudo apt-get install libfreetype6-dev and then repeat 3.

Alternative way:

# Grab source
hg clone https://bitbucket.org/pygame/pygame

# Finally build and install
cd pygame
python setup.py build
sudo python setup.py install
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Pratyush
  • 5,108
  • 6
  • 41
  • 63
  • 1
    Worked for me on ubuntu 14.04. Building/installing it like this could be an accepted answer for pygame project. – Yauhen Yakimovich Jun 11 '14 at 12:41
  • 5
    Worked for me. It's still a little silly that Pygame doesn't have a proper release on PyPI... – Cerin Oct 27 '14 at 23:12
  • 1
    `pip3 install hg+http://bitbucket.org/pygame/pygame` works well with Python 3.4.2 on Ubuntu 14.10 once you have all the dependencies installed. Since `ffmpeg` is currently not available as a package, I had to build it from source first (more dependencies needed...), but once that was done the pygame installation worked like a charm. Interestingly, cloning the repo and running `python3 setup.py build` did **not** work, for some reason, but pip did. Go figure... – MattDMo Nov 21 '14 at 17:17
  • 1
    On my system (Ubuntu 15.10 running in VirtualBox), command #3 silently waited me to press Enter after cloning the package. After I pressed it, the installation process promptly began. – nfgf Feb 13 '16 at 16:00
  • 2
    I'm confused. Why so many upvotes, when this is for the wrong OS? OP is using windows, so sudo won't work. – Oddthinking May 09 '16 at 15:04
  • 1
    @Oddthinking First two steps are only for Linux. Window's executable installer is provided just above step 3. – Pratyush May 09 '16 at 16:46
  • 1
    brew install homebrew/python/pygame – Madmint Jun 26 '16 at 05:14
  • This comment is incorrect in using bitbucket, as pygame moved to github a couple of years ago. – René Dudfield Aug 27 '18 at 09:51
22

Try doing this:

sudo apt-get install mercurial
sudo pip install hg+http://bitbucket.org/pygame/pygame
BoJack Horseman
  • 4,406
  • 13
  • 38
  • 70
Arun G
  • 1,678
  • 15
  • 17
18

An update to this may be required, as it stands in version 1.9.1 it should simply install using:

pip install pygame

However, it look like there is a bug with their pypi repository, see: https://bitbucket.org/pygame/pygame/issues/59/pygame-has-no-pypi-page-and-cant-be

So, if you want the most recent release, you have to point directly at the ftp file ala:

pip install http://www.pygame.org/ftp/pygame-1.9.1release.tar.gz

I suppose this will be fixed in the 1.9.2 release but for now this works.

I would note that the answer supplied by Pratyush works as well, but requires the user to install mercurial if they don't have it and downloads the trunk version, so really, not ideal unless you absolutely need it.

Daniel Kuntz
  • 405
  • 4
  • 11
10

Caveat: I'm not familiar with the Enthought Distribution, so this might not help.

As you're trying to install on Windows, if you don't want to have to mess around with C compilers, there are pre-built binary wheels for pygame here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame

Select a package appropriate to you python version[0] and Windows architecture [1]. Download to C:\Users\User\Download\pip install E:\env\pygame-1.9.2a0-cp27-none-win_amd64.whl and install with pip install E:\env\pygame-1.9.2a0-cp27-none-win_amd64.whl

Mercurial binaries can be found on the same page, if you would like to install from source. This method would mean compiling pygame from source, for which you probably want to use this compiler package.

[0] python --version

[1] powershell "gwmi win32_operatingsystem | select osarchitecture"

laffoyb
  • 1,540
  • 3
  • 22
  • 35
7

The command below worked for me on Mac OS X El Capitan:

pip3 install pygame

voices
  • 495
  • 6
  • 20
Zeke
  • 134
  • 1
  • 4
6

Install on MAC:

brew install homebrew/python/pygame
Nizar B.
  • 3,098
  • 9
  • 38
  • 56
  • 1
    I'm under OS X EI Capitan, this solution doesn't work : `/usr/local/include/pngconf.h:45:12: fatal error: 'stdio.h' file not found` – Bin Jun 27 '16 at 12:54
5

Just

sudo pip install pygame

worked for me

5

Had this issue on macOS Sierra, where apt-get doesn't work.

Managed to solve the issue through the following steps:

First I had to install the Mercurial via Brew:

brew install mercurial

Then, I had to install Pygame dependencies:

brew install sdl sdl_image sdl_mixer sdl_ttf smpeg portmidi

Finally I used pip3 to install Pygame:

pip3 install pygame

Hope this helps!

daveliew
  • 75
  • 2
  • 7
5

The most current, the best way to install pygame is always available at: https://www.pygame.org/wiki/GettingStarted

How to use pip depends on the operating system. So unless you have always updated and tested answers for 15 different operating systems then just send people to that page. All answers to this question are wrong for various different operating systems.

Currently, for windows, this is the way to install it in the cmd prompt. (If you already have pip installed, and people know what pip is... best just send people to the GettingStarted page).

py -m pip install pygame --user

René Dudfield
  • 591
  • 4
  • 10
5

Try

python3 -m pip install -U pygame --user

This worked twice for me on windows 7 and windows 10

Guydangerous99
  • 147
  • 1
  • 12
4

I did use these instructions here from the official site.
But i had to change the python3 part of the command to just py.

Bjamse
  • 333
  • 5
  • 17
3

Try: python -m pip install pygame

Or: py -m pip install pygame

Armster
  • 772
  • 1
  • 9
  • 25
3

Try pip install pygame or pip3 install pygame.

These should work for you.

If this does not work for you put -m before pip and python before -m.

If putting -m does not work try reinstalling python

3

If you are working on windows, the command below should work fine

 pip install pygame

If you are working on Linux, the command below should work fine

sudo apt-get install python-pygame
3

Type this in command prompt

pip install pygame

or

py -m pip install pygame

3

WINDOWS

If you are on a windows 10 device then you should use this command but first make sure you have Python installed from https://python.org, if you do run this in command prompt

py --version

and then whatever version it says you have (which you downloaded) keep it in mind we will use it later for now just incase try to upgrade pip incase you are on a outdated version I will be using 3.9 for the version for the rest of this as an example

py -3.9 -m pip --upgrade pip

After that if you have it already satisfied or it upgraded run this command in command prompt

py -3.9 -m pip install pygame

And wait for it to download And to make sure it worked run this

py -3.9 -m pygame --version

If it shows the version you downloaded it!

MacOS

For MacOS do the same but then run this command to install it

python3 -m pip install -U pygame --user

or if it wont work

py -3.9 -m pip install -U pygame --user      ( or just pip3 )

to see if it worked run this

python3 -m pygame.examples.aliens

or

py -3.9 -m pygame.examples.aliens

I hope this helped

Ryan's World
  • 70
  • 10
2

I have never used Enthought distribution, but you could try to use Anaconda distribution which is also great too.

Anaconda Distribution (Any OS):

From the docs:

Update conda to the current version. Type the following:

conda update conda

If a newer version of conda is available, type y to update: Proceed ([y]/n)? y

Check to see if a package you have not installed named “pygame” is available from the Anaconda repository (must be connected to the Internet):

conda search pygame

Conda displays a list of all packages with that name on the Anaconda repository, so we know it is available.

Install this package into the current environment:

conda install pygame

Check to see if the newly installed program is in this environment:

conda list

Install on Windows (both python 2.7 and 3.7):

pip install pygame 

Install on raspberry pi:

sudo pip3 install pygame (python 3.7)
sudo pip install pygame (python 2.7)
2

I think if you go to Command Prompt and type

py -m pip install pygame

that's what works for me

Miffuine
  • 31
  • 2
2

Here is a way: sudo install pygame Rasberry pi has it ready-installed

Psychzander
  • 107
  • 14
2

Install python 3.8 from python.org Then install pygame (2.0) like this pip install pygame==2.0.0.dev10

PythonProgrammi
  • 22,305
  • 3
  • 41
  • 34
2

Make sure script path is registered in environment variables, Make sure the python path is registered in environment variables, also you dont have to enter entire url just write like this(windows only I dont use mac)

pip
pip install pygame

hope it work

  • This answer is no different than most of the other 28 answers. [From Review](https://stackoverflow.com/review/late-answers/29667684) – Trenton McKinney Aug 27 '21 at 16:54
2

command to install pygame is:

pip install pygame

run it in command prompt

1

Try doing this for python3:

python3 -m pip install pygame==1.9.6

and this for python2:

python -m pip install pygame==1.9.6
WinstonMan
  • 132
  • 1
  • 13
1

To install pygame with pip, use the following commands in the Command Prompt on Windows.

py -m pip download pygame

then...

py -m pip install pygame

You only have to do the download pygame one if it doesn't work when you use the install pygame command by itself.

You type py -m to show that it is using the module pip, which can be accessed through the command prompt.

This is for Windows. For Mac OS, use python -m pip install pygame

SamTheProgrammer
  • 1,051
  • 1
  • 10
  • 28
1

You don't have to type in the entire url. Just simply go to command prompt (windows) or terminal (mac) and then type in:

[windows] pip install pygame [mac] python -m install pygame

hopefully that works :)

Charlie C
  • 180
  • 8
1

I know that there are already lot's of answers, but if you want to download a specific version of pygame, you can use pip:

pip install pygame==1.9.6

Pygame 1.9.6 is the latest version at the time of writing.

theProCoder
  • 390
  • 6
  • 21
0

Pygame tells you how to install it here, in my personal experience this is what I do on windows to install it, open up command prompt and type python -m pip install pygame if that fails, check if you have more than one version of python installed if so you need to specify what version for example python3.5 -m pip install pygame the reason we do this from command prompt is that in the Python shell it doesn't understand what pip install is just to break it down a little python -m calls a python module in this case we want pip the next two arguments are what we want pip to do and what module/addon we want the action to be applied too

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 21 '22 at 14:41
  • @Community I disagree that my answer is unclear I clearly include a link to pygame's official installation instructions and then continue on to explain my personal experience of installing the module including when I've had more than one version of python on my computer I then explain why we don't do it in python's shell and what the command actually does I also was reading the "how to write good answers" while making the comment or I'd of just said hey do this – Daniel Neonzz Young Nov 02 '22 at 13:04
0

First you have to run command prompt in administrator mode. To run in administrator mode:

  1. Type command prompt in Windows search bar.
  2. Right click on the command prompt option and click 'Run as administrator'.
  3. Windows will ask you if you want to allow the app to make changes to your device. Click 'Yes'.
  4. Command prompt will open in administrator mode.

Then type the following:

pip3 install pygame
Dinux
  • 644
  • 1
  • 6
  • 19