Unable to install Pygame using pip

2019-01-08 16:28发布

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.

14条回答
可以哭但决不认输i
2楼-- · 2019-01-08 16:46

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!

查看更多
疯言疯语
3楼-- · 2019-01-08 16:47

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"

查看更多
时光不老,我们不散
4楼-- · 2019-01-08 16:47

Install on MAC:

brew install homebrew/python/pygame
查看更多
老娘就宠你
5楼-- · 2019-01-08 16:47

The most current, 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 updating 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

查看更多
成全新的幸福
6楼-- · 2019-01-08 16:52

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
查看更多
做个烂人
7楼-- · 2019-01-08 16:53

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

pip3 install pygame

查看更多
登录 后发表回答