Python 无法使用 pip 安装 Pygame

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17869101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 09:21:17  来源:igfitidea点击:

Unable to install Pygame using pip

pythonpygameinstallpip

提问by NumberOneRobot

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:

我正在尝试安装 Pygame。我正在使用 Enthought Python Distribution 运行 Windows 7。我成功安装了pip,但是当我尝试使用 安装 Pygame 时pip,出现以下错误:

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

“由于 HTTP 错误 HTTP 错误 400:对 URL 的错误请求,无法安装要求 Pygame...”

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:

我无法通过 Google 搜索找到有关此问题的任何信息,但我确实找到了另一个 Stack Overflow 问题,该问题提示提问者使用以下命令:

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.

我不知道还能做什么,因为我在 Google 搜索中找到的所有内容都是针对 Mac 的,所以我不知道我在 Windows 上如何按照这些说明进行操作。

回答by Pratyush

Steps to install PyGame using pip

使用 pip 安装 PyGame 的步骤

  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 founderror (on Linux), then try sudo apt-get install libfreetype6-devand then repeat 3.

  1. 安装构建依赖项(在 linux 上):

    sudo apt-get build-dep python-pygame
    
  2. 安装 mercurial 以使用hg(在 linux 上):

    sudo apt-get install mercurial
    

    在 Windows 上,您可以使用安装程序:下载

  3. 使用 pip 安装 PyGame:

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

    如果以上给出freetype-config: not found错误(在 Linux 上),则尝试sudo apt-get install libfreetype6-dev然后重复 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

回答by Arun G

Try doing this:

尝试这样做:

sudo apt-get install mercurial
sudo pip install hg+http://bitbucket.org/pygame/pygame

回答by laffoyb

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

警告:我不熟悉 Enthought 发行版,所以这可能无济于事。

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

当您尝试在 Windows 上安装时,如果您不想弄乱 C 编译器,这里有预先构建的 pygame 二进制轮子: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.whland install with pip install E:\env\pygame-1.9.2a0-cp27-none-win_amd64.whl

选择适合您的包 python 版本 [0] 和 Windows 体系结构 [1]。下载C:\Users\User\Download\pip install E:\env\pygame-1.9.2a0-cp27-none-win_amd64.whl并安装pip install E:\env\pygame-1.9.2a0-cp27-none-win_amd64.whl

Mercurial binariescan 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.

如果您想从源代码安装,可以在同一页面上找到Mercurial 二进制文件。这种方法意味着从源代码编译 pygame,为此您可能想使用这个编译器包

[0] python --version

[0] python --version

[1] powershell "gwmi win32_operatingsystem | select osarchitecture"

[1] powershell "gwmi win32_operatingsystem | select osarchitecture"

回答by Daniel Kuntz

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

可能需要对此进行更新,因为它位于 1.9.1 版中,只需使用以下命令进行安装:

pip install pygame

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

但是,看起来他们的 pypi 存储库存在错误,请参阅: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:

所以,如果你想要最新的版本,你必须直接指向 ftp 文件 ala:

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

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.

我想这将在 1.9.2 版本中修复,但现在这有效。

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.

我会注意到 Pratyush 提供的答案也有效,但是如果用户没有安装 mercurial 并下载主干版本,则要求用户安装它,因此除非您绝对需要,否则并不理想。

回答by Nizar B.

Install on MAC:

在 MAC 上安装:

brew install homebrew/python/pygame

回答by Zeke

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

下面的命令在 Mac OS X El Capitan 上对我有用:

pip3 install pygame

pip3 install pygame

回答by Sébastien de craene

Just

只是

sudo pip install pygame

worked for me

为我工作

回答by daveliew

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

在 macOS Sierra 上有这个问题,其中 apt-get 不起作用。

Managed to solve the issue through the following steps:

通过以下步骤设法解决了问题:

First I had to install the Mercurial via Brew:

首先,我必须通过 Brew 安装 Mercurial:

brew install mercurial

Then, I had to install Pygame dependencies:

然后,我必须安装 Pygame 依赖项:

brew install sdl sdl_image sdl_mixer sdl_ttf smpeg portmidi

Finally I used pip3 to install Pygame:

最后我使用 pip3 来安装 Pygame:

pip3 install pygame

Hope this helps!

希望这可以帮助!

回答by René Dudfield

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

安装 pygame 的最新、最佳方法始终可用: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.

如何使用 pip 取决于操作系统。因此,除非您一直更新和测试 15 种不同操作系统的答案,否则只需将人们发送到该页面即可。对于各种不同的操作系统,这个问题的所有答案都是错误的。

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

目前,对于 Windows,这是在 cmd 提示符下安装它的方式。(如果您已经安装了 pip,并且人们知道 pip 是什么......最好只是将人们发送到 GettingStarted 页面)。

py -m pip install pygame --user

py -m pip install pygame --user

回答by Bjamse

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

我没有使用这些指令在这里从官方网站。
但是我不得不将命令的 python3 部分更改为 py。