简体   繁体   English

无法使用pip安装Pygame

[英]Unable to install Pygame using pip

I'm trying to install Pygame.我正在尝试安装 Pygame。 I am running Windows 7 with Enthought Python Distribution.我正在使用 Enthought Python Distribution 运行 Windows 7。 I successfully installed pip , but when I try to install Pygame using pip , I get the following error:我成功安装了pip ,但是当我尝试使用pip安装 Pygame 时,出现以下错误:

"Could not install requirement Pygame because of HTTP error HTTP error 400: Bad request for URL..." “无法安装要求 Pygame,因为 HTTP 错误 HTTP 错误 400: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:我无法通过 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 上如何按照这些说明进行操作。

Steps to install PyGame using pip使用 pip 安装 PyGame 的步骤

  1. Install build dependencies (on linux):安装构建依赖项(在 linux 上):

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

     sudo apt-get install mercurial

    On Windows you can use the installer: Download在 Windows 上,您可以使用安装程序:下载

  3. Use pip to install PyGame:使用 pip 安装 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.如果上面给出了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

Try doing this:尝试这样做:

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

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

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

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 并下载主干版本,则要求用户安装它,因此除非您绝对需要,否则并不理想。

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].选择适合您的包 python 版本 [0] 和 Windows 体系结构 [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下载到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 binaries can be found on the same page, if you would like to install from source.如果您想从源代码安装,可以在同一页面上找到Mercurial 二进制文件 This method would mean compiling pygame from source, for which you probably want to use this compiler package .这种方法意味着从源代码编译 pygame,为此您可能想使用 这个编译器包

[0] python --version [0] python --version

[1] powershell "gwmi win32_operatingsystem | select osarchitecture" [1] powershell "gwmi win32_operatingsystem | select osarchitecture"

在 MAC 上安装:

brew install homebrew/python/pygame

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

pip3 install pygame

Try尝试

python3 -m pip install -U pygame --user

This worked twice for me on windows 7 and windows 10这在 Windows 7 和 Windows 10 上对我有用两次

Just只是

sudo pip install pygame

worked for me为我工作

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!希望这可以帮助!

The most current, the 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.如何使用 pip 取决于操作系统。 So unless you have always updated and tested answers for 15 different operating systems then just send people to that page.因此,除非您一直更新和测试 15 种不同操作系统的答案,否则只需将人们发送到该页面即可。 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.目前,对于 Windows,这是在 cmd 提示符下安装它的方式。 (If you already have pip installed, and people know what pip is... best just send people to the GettingStarted page). (如果您已经安装了 pip,并且人们知道 pip 是什么......最好只是将人们发送到 GettingStarted 页面)。

py -m pip install pygame --user

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。

I have never used Enthought distribution, but you could try to use Anaconda distribution which is also great too.我从未使用过 Enthought 发行版,但您可以尝试使用 Anaconda 发行版,这也很棒。

Anaconda Distribution (Any OS): Anaconda 发行版(任何操作系统):

From the docs:从文档:

Update conda to the current version.将 conda 更新到当前版本。 Type the following:键入以下内容:

conda update conda

If a newer version of conda is available, type y to update: Proceed ([y]/n)?如果有更新版本的 conda 可用,请键入 y 进行更新: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):检查 Anaconda 存储库中是否有一个您尚未安装的名为“pygame”的包(必须连接到 Internet):

conda search pygame

Conda displays a list of all packages with that name on the Anaconda repository, so we know it is available. Conda 在 Anaconda 存储库中显示具有该名称的所有包的列表,因此我们知道它可用。

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):在 Windows 上安装(python 2.7 和 3.7):

pip install pygame 

Install on raspberry pi:在树莓派上安装:

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

Try: python -m pip install pygame尝试: python -m pip install pygame

Or: py -m pip install pygame或者: py -m pip install pygame

I think if you go to Command Prompt and type我想如果你去命令提示符并输入

py -m pip install pygame

that's what works for me这对我有用

Try pip install pygame or pip3 install pygame .尝试pip install pygamepip3 install pygame

These should work for you.这些应该对你有用。

If this does not work for you put -m before pip and python before -m .如果这不工作,你把-m之前, pippython之前-m

If putting -m does not work try reinstalling python如果放置-m不起作用,请尝试重新安装 python

这是一种方法: sudo install pygame Rasberry pi has it ready-installed

If you are working on windows, the command below should work fine如果你在 Windows 上工作,下面的命令应该可以正常工作

 pip install pygame

If you are working on Linux, the command below should work fine如果你在 Linux 上工作,下面的命令应该可以正常工作

sudo apt-get install python-pygame

Type this in command prompt在命令提示符中输入这个

pip install pygame

or要么

py -m pip install pygame

command to install pygame is:安装pygame的命令是:

pip install pygame

run it in command prompt在命令提示符下运行它

Try doing this for python3:尝试为 python3 执行此操作:

python3 -m pip install pygame==1.9.6

and this for python2:这对于python2:

python -m pip install pygame==1.9.6

从 python.org 安装 python 3.8 然后像这样安装 pygame (2.0) pip install pygame==2.0.0.dev10

To install pygame with pip , use the following commands in the Command Prompt on Windows.要使用pip安装pygame ,请在 Windows 上的Command Prompt使用以下命令。

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.如果单独使用install pygame命令不起作用,则只需download pygame一个。

You type py -m to show that it is using the module pip , which can be accessed through the command prompt.您键入py -m以显示它正在使用模块pip ,该模块可以通过命令提示符访问。

This is for Windows.这是针对 Windows 的。 For Mac OS, use python -m pip install pygame对于 Mac 操作系统,使用python -m pip install pygame

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)或终端(mac),然后输入:

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

hopefully that works :)希望有效:)

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)确保脚本路径在环境变量中注册,确保python路径在环境变量中注册,你也不必输入整个url就这样写(只有windows我不使用mac)

pip
pip install pygame

hope it work希望它有效

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:我知道已经有很多答案了,但是如果您想下载特定版本的 pygame,您可以使用 pip:

pip install pygame==1.9.6

Pygame 1.9.6 is the latest version at the time of writing. Pygame 1.9.6 是撰写本文时的最新版本。

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如果你使用的是 Windows 10 设备,那么你应该使用这个命令,但首先确保你从https://python.org安装了 Python,如果你在命令提示符下运行它

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然后它说你拥有的任何版本(你下载的)记住它我们稍后会使用它只是为了防止尝试升级pip,以防你使用的是过时的版本我将使用3.9作为这个版本的其余部分举个例子

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对于 MacOS 执行相同操作,然后运行此命令进行安装

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我希望这有帮助

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 Pygame 告诉你如何在这里安装它,根据我个人的经验,这是我在 windows 上安装它时所做的,打开命令提示符并键入python -m pip install pygame如果失败,请检查你是否有多个版本的 python如果安装了,你需要指定什么版本,例如python3.5 -m pip install pygame我们从命令提示符执行此操作的原因是在 Python shell 中它不理解什么 pip install 只是为了将它分解成一个小 python -m 在这种情况下调用 python 模块我们想要 pip 接下来的两个参数是我们想要 pip 做什么以及我们想要应用操作的模块/插件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM