问题描述
我正在尝试在Mac上安装pygame
,当我导入pygame
时,返回以下错误
I'm trying to install pygame
on my mac, when I import pygame
, below error returned
Traceback (most recent call last): File "<pyshell#0>", line 1,
in <module> import pygame File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py", line 95,
in <module> from pygame.base import * ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so, 2): no suitable image found.
Did find: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so: no matching architecture in universal wrapper.
我已经看到这是一个体系结构问题,但是我不知道如何安装32位python.
I have seen it is a architecture problem, however I'm not aware of how to install 32bit python.
预先感谢
推荐答案
我意识到这些步骤最初是针对python3的.它仍然适用于python2,但我无法确认,这只是我的最佳答案.
I realized that these steps were originally intended for python3. It should still work for python2, but I can't confirm, it's just the best answer I have.
假设您使用的是最新的macOS,这是我用来安装pygame的步骤.尝试卸载以前为pygame安装的软件,我不确定这会如何影响它.如果您还没有IDLE程序,它将安装python开发的python IDE.
Assuming you are using the newest macOS, here are the steps I used to install pygame. Try and uninstall what you installed for pygame previously, I'm not sure how this could affect it. This will also install the IDLE program, a python IDE developed by python, if you don't already have it.
如果您使用的是较旧的Mac,请单击底部的源链接,我们会提供有关较旧的mac的说明,其中包括下载xcode之类的程序.
If you have an older mac, click the source link at the bottom, which we provide instructions for older macs, which would involve downloading programs like xcode.
-
安装自制软件.进入终端并粘贴
Install homebrew. Go into terminal and paste
ruby -e "$(curl -fsSL https<nolink>://raw.githubusercontent.com/Homebrew/install/master/install)"
然后按Enter.
将以下内容粘贴到终端中,在每一行之后按回车键:
Paste the following into terminal, hitting enter after each line:
brew install python
(对于python3用户为brew install python3
)
brew install python
(brew install python3
for python3 users)
brew install mercurial
brew install sdl sdl_image sdl_mixer sdl_ttf portmidi
brew tap homebrew/headonly
(如果您在此处遇到任何麻烦,请尝试使用brew install --HEAD smpeg
)
brew tap homebrew/headonly
(if you have any trouble here, try brew install --HEAD smpeg
instead)
brew install smpeg
sudo -H pip install hg+http<nolink>://bitbucket.org/pygame/pygame
(您必须输入密码,并且您必须是管理员.Python3用户应使用sudo -H pip3 install hg+http<nolink>://bitbucket.org/pygame/pygame
)
sudo -H pip install hg+http<nolink>://bitbucket.org/pygame/pygame
(You will have to enter your password, and you must be an admin. Python3 users should use sudo -H pip3 install hg+http<nolink>://bitbucket.org/pygame/pygame
)
这篇关于无法在Mac上安装pygame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!