找不到pygame

发布于 2024-09-10 04:10:46 字数 354 浏览 11 评论 0原文

我在 ubuntu 中运行,我可以用 python 编写代码,没有问题。我尝试安装 pygame 并做到这一点,我这样做了:

sudo apt-get 安装 python-pygame

当我进入 python IDLE 并写入:

导入pygame

我得到:

回溯(最近一次调用最后一次):

文件“”,第 1 行,位于

导入错误:没有名为 pygame 的模块

我能做些什么来解决这个问题?我忘记了什么,或者做错了什么?

I am running in ubuntu and I can code in python, without problem. I have tried to install pygame and to do make it so, I did:

sudo apt-get instal python-pygame

When I go into the python IDLE and write:

import pygame

I get:

Traceback (most recent call last):

File "", line 1, in

ImportError: No module named pygame

What can I do to solve this problem? I am forgetting something, or doing something wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

属性 2024-09-17 04:10:46

apt-get 将为已注册且 pygame-package 支持的 Python 版本安装 pygame。执行

ls -1 /usr/lib/python*/site-packages/pygame/__init__.pyc

以找出是哪个。在我的旧 debian 系统上,打印

/usr/lib/python2.4/site-packages/pygame/__init__.pyc
/usr/lib/python2.5/site-packages/pygame/__init__.pyc

That 意味着如果我不使用 Python 2.4 或 Python 2.5,pygame 将不可用。 IDLE 正在使用的 Python 版本应显示在顶部(您也可以使用 import sys; print(sys.version) 查看它)。

您可以手动安装 pygame 或尝试添加已安装的版本,具体

import sys
sys.path.append('/usr/lib/python2.5/site-packages/')
import pygame

取决于加载模块的复杂性(在您的情况下是 pygame),但这可能会在以后引起一些问题。

apt-get will install pygame for the registered and pygame-package-supported Python versions. Execute

ls -1 /usr/lib/python*/site-packages/pygame/__init__.pyc

to find out which. On my old debian system, that prints

/usr/lib/python2.4/site-packages/pygame/__init__.pyc
/usr/lib/python2.5/site-packages/pygame/__init__.pyc

That means if I'm not using either Python 2.4 or Python 2.5, pygame will not be available. The Python version your IDLE is using should be displayed at the top (you can also see it with import sys; print(sys.version)).

You can either manually install pygame or try to add the installed version with

import sys
sys.path.append('/usr/lib/python2.5/site-packages/')
import pygame

Depending on the complexity of the loaded module(pygame in your case), this might cause some problems later though.

葬心 2024-09-17 04:10:46

如果您不喜欢下载解压后手动安装,可以使用 apt 安装 setuptools 。之后你可以使用easy_install(或easy_install-2.7?)来安装许多Python包,当然包括pygame。

If you don't like to download an unpack then install manually, you can use apt to install setuptools . After that you can use easy_install(or easy_install-2.7?) to install many python packages, including pygame, of course.

赴月观长安 2024-09-17 04:10:46

我刚刚遇到了同样的问题!

我读了这篇文章,虽然它可以完成 sys.path.append 的事情,但我决定尝试让它工作。

我所做的就是去Ubuntu软件中心卸载我已经安装的python IDLE,然后安装IDLE。

这似乎令人困惑,我说的方式是为了澄清你想要下载不附带自己版本的Python的IDLE,然后它将使用Ubuntu已经附带的Python!

如果此后不起作用或无法帮助解决您的问题,请告诉我!

I just had this same problem!

I read this and while it works to do the sys.path.append thing, I decided to try and get it to work with out.

What I did was went to the Ubuntu Software center uninstalled the python IDLE i had installed and then installed the IDLE.

This seems confusing the way I said it so to clarify you want to download the IDLE that doesn't come with its own version of python, it'll then use the python that already comes with Ubuntu!

If this doesn't make since or doesn't help fix your problem let me know!

成熟的代价 2024-09-17 04:10:46

检查您安装的 pygame 是否适用于正确的 Python 版本。我认为 python 2.7 的 pygame 无法在 python 3.3 上运行。我遇到了同样的问题,但即使安装了正确的版本后它也不起作用。因此,经过一番谷歌搜索后,我发现我正在安装 32 位的 pygame,但我的操作系统是 64 位的。所以尝试用谷歌搜索“pygame for window 64-bit”或类似的东西。我希望它有帮助。

check that you are installing pygame for the right version of python. I think the pygame for python 2.7 won't work on python 3.3. I had the same problem but even after installing the right version it didn't work. So after a little googling I found that I was installing pygame meant for 32-bit but my os is 64-bit. so try to google "pygame for window 64-bit" or something like that. I hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文