如何下载 Python 3.5.1 的 Pygame?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35609592/
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 16:40:39  来源:igfitidea点击:

How do I download Pygame for Python 3.5.1?

pythonpython-3.xpygame

提问by Utnapishtum

I am unable to find a pygame download for Python 3.5 and the ones I have downloaded don't seem to work when I import to the shell. Help?

我找不到 Python 3.5 的 pygame 下载,而且我下载的那些在导入到 shell 时似乎不起作用。帮助?

This is the message I receive on the shell:

这是我在外壳上收到的消息:

import pygame Traceback (most recent call last): File "", line 1, in import pygame ImportError: No module named 'pygame'

导入 pygame 回溯(最近一次调用):文件“”,第 1 行,导入 pygame 导入错误:没有名为“pygame”的模块

回答by Utnapishtum

I'm gonna guess your using Windows. If you are not then there is no special version of pygame for Python 3+. If you do have Windows then read below.

我猜你用的是 Windows。如果不是,则没有适用于 Python 3+ 的特殊版本的 pygame。如果您有 Windows,请阅读以下内容。

You will need pygame to be part of your path to do this. This is so you can use this in the command prompt. Make sure you use it as an admin when doing this.

您将需要 pygame 成为您执行此操作的路径的一部分。这样您就可以在命令提示符中使用它。确保在执行此操作时将其用作管理员。

First you need to find out what bit version of Python you have. Open your Python shell and at the top of the window it should say something like "Pygame V(some number) (bit number)" You want the bit number.

首先,您需要找出您拥有的 Python 版本。打开你的 Python shell,在窗口的顶部,它应该会写一些类似“Pygame V(some number) (bit number)”的内容。你想要这个数字。

Now you ned to open the command prompt. Use the "windows key + r key" to open the run menu, and type "cmd" and press enter. Or you can just search your PC for "cmd" and right click on it and select "run as admin" to open as an admin.

现在您需要打开命令提示符。使用“windows键+r键”打开运行菜单,输入“cmd”回车。或者您可以在您的 PC 上搜索“cmd”并右键单击它并选择“以管理员身份运行”以管理员身份打开。

Python comes with a special path command called "pip." I am not gonna get into this module too much, but in short it is used to install addition Python modules. The first thing you need to do is this command...

Python 附带了一个名为“pip”的特殊路径命令。我不会过多地介绍这个模块,但简而言之,它用于安装附加的 Python 模块。你需要做的第一件事就是这个命令......

pip install wheel

The screen should print some stuff off while doing this. You can tell if the module installed correctly because it should print something like "wheel installed successfully." We are gonna need this later.

执行此操作时,屏幕应打印一些内容。您可以判断模块是否安装正确,因为它应该打印类似“wheel installed successfully”的内容。我们稍后会需要这个。

Now you need to get your pygame file. Go hereand find the pygame section. If you have python 32 bit download you should download this "pygame-1.9.2b1-cp35-cp35m-win32.whl" or if you have 64 bit Python download "pygame-1.9.2b1-cp35-cp35m-win_amd64.whl". I am pretty sure these are the ones you need for your bit version, but I installed pygame on my Windows 10 a few months ago so they may be different now.

现在你需要得到你的 pygame 文件。去这里找到 pygame 部分。如果你有 python 32 位下载,你应该下载这个“pygame-1.9.2b1-cp35-cp35m-win32.whl”或者如果你有 64 位 Python 下载“pygame-1.9.2b1-cp35-cp35m-win_amd64.whl”。我很确定这些是你的 bit 版本所需要的,但几个月前我在我的 Windows 10 上安装了 pygame,所以它们现在可能会有所不同。

Once you have this downloaded go back to the command prompt. Enter this command...

下载后,返回命令提示符。输入这个命令...

pip install (filename)

Make sure it includes the .whl extension. If you get an error then specify the path to the folder the file is in (which should be the downloads folder). Once again you should see a message similar to "pygame installed successfully."

确保它包含 .whl 扩展名。如果出现错误,请指定文件所在文件夹的路径(应该是下载文件夹)。您应该再次看到类似于“pygame 安装成功”的消息。

Once all this is done open your Python shell and type...

完成所有这些后,打开您的 Python shell 并键入...

import pygame

If it works you now have pygame available for use. If not then there are a few more things you can try...

如果它有效,您现在可以使用 pygame。如果没有,那么你可以尝试更多的东西......

  1. Try restarting your PC. Sometimes these things don't take affect until a system restart.
  2. Try installing a different version of pygame from the website listed above. It may just be a simple issue due to bit version differences.
  3. Make sure you actually installed the pygame module from the file. It may of thrown an error that appeared to be an actual successful installation. It always pays to double-check.
  1. 尝试重新启动您的 PC。有时这些事情在系统重新启动之前不会生效。
  2. 尝试从上面列出的网站安装不同版本的 pygame。由于位版本差异,这可能只是一个简单的问题。
  3. 确保您确实从该文件安装了 pygame 模块。它可能会抛出一个错误,似乎是实际安装成功。仔细检查总是值得的。

Like I said before I installed pygame on my Windows 10 with Python 3.4 64 bit a few months ago in the same way I told you here so it should work, but may be outdated. Anyways I hope this helps you with your pygame installation issues and the best of luck to you!

就像我几个月前用 Python 3.4 64 位在我的 Windows 10 上安装 pygame 之前所说的,就像我在这里告诉你的那样,所以它应该可以工作,但可能已经过时了。无论如何,我希望这可以帮助您解决 pygame 安装问题,并祝您好运!

回答by Karl The Coder

Even when you have windows 64 bit you need to get the win32.whl file , then follow the standard instructions

即使您使用的是 64 位 Windows,您也需要获取 win32.whl 文件,然后按照标准说明进行操作

回答by Mothbawls

For windows now you simply use pip as it's available directly to install as pygame.

对于 Windows,您现在只需使用 pip,因为它可以直接安装为 pygame。

Use the following command:

使用以下命令:

python -m pip install pygame

It should output something like this, then you can test if it's working by importing pygame.

它应该输出这样的东西,然后你可以通过导入 pygame 来测试它是否工作。

PS C:\Windows\system32> python -m pip install pygame
Collecting pygame
  Downloading pygame-1.9.2b1-cp35-cp35m-win32.whl (4.4MB)
  100% |################################| 4.4MB 264kB/s
Installing collected packages: pygame
Successfully installed pygame-1.9.2b1
PS C:\Windows\system32> python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
# Note there is no error here...
>>> quit()
PS C:\Windows\system32>

回答by sparskter

This worked preety well for me:

这对我来说效果很好:

System:Ubuntu 16.10 x64

系统:Ubuntu 16.10 x64

root@sonic-VirtualBox:~/python# cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.10
DISTRIB_CODENAME=yakkety
DISTRIB_DESCRIPTION="Ubuntu 16.10"
NAME="Ubuntu"
VERSION="16.10 (Yakkety Yak)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.10"
VERSION_ID="16.10"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="http://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=yakkety
UBUNTU_CODENAME=yakkety
root@sonic-VirtualBox:~/python# 

Python 2.7 + Pygame:

Python 2.7 + Pygame:

root@sonic-VirtualBox:~/python# python -V
Python 2.7.12+
# apt-get install python-pip
# pip install --upgrade pip
# pip install pygame

Python 3.5 + Pygame: (Python 3.5.2+ in my case)

Python 3.5 + Pygame:(在我的例子中是 Python 3.5.2+)

root@sonic-VirtualBox:~/python# python3 -V
Python 3.5.2+

# sudo apt-get install python3-pip
# pip3 install --upgrade pip
# pip3 install pygame

回答by the green penguin

Download to pygame3.5

下载到pygame3.5

Then put this into your cmd

然后把它放到你的cmd中

cd [location of python3.5]
python -m pip install [location of pygame]
python -m pip install --upgrade pip

Then type

然后输入

import pygame
pygame.init()

回答by calocedrus

In an anaconda environment with python 3.5 installed, you can simply do:

在安装了 python 3.5 的 anaconda 环境中,您可以简单地执行以下操作:

pip install pygame

pip install pygame

$pip install pygame
Collecting pygame
  Downloading pygame-1.9.3-cp35-cp35m-manylinux1_x86_64.whl (9.4MB)
    100% |***************************| 9.4MB 132kB/s 
Installing collected packages: pygame
Successfully installed pygame-1.9.3

I'm in ubuntu 14.04, this should work with newer and other linuxes.

我在 ubuntu 14.04,这应该适用于较新的和其他 linuxes。