繁体   English   中英

在 Mac 上安装 pygame 时出现 sdl.h 错误?

[英]sdl.h error when installing pygame on Mac?

我正在尝试安装 pygame。

我的环境是

macOS 10.14.6 莫哈维

Python 3.7.4(从 python.org 下载)

我正在按照 Pygame 网站上的说明进行操作,即使用

pip install pygame

然而,这是失败的致命错误,可以总结为致命错误:SDL.h filenot found完整的安装输出如下所示。

Running setup.py install for pygame ... error
ERROR: Command errored out with exit status 1:
 command: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-mtm_fm2t/pygame/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-mtm_fm2t/pygame/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/tmp/pip-record-vrvsxslr/install-record.txt --single-version-externally-managed --compile
     cwd: /private/tmp/pip-install-mtm_fm2t/pygame/
Complete output (219 lines):
running install
running build
running build_py
creating build
creating build/lib.macosx-10.9-x86_64-3.8
creating build/lib.macosx-10.9-x86_64-3.8/pygame
copying src_py/surfarray.py -> build/lib.macosx-10.9-x86_64-3.8/pygame
copying src_py/sysfont.py -> build/lib.macosx-10.9-x86_64-3.8/pygame
copying src_py/_camera_vidcapture.py -> build/lib.macosx-10.9-x86_64-3.8/pygame

...whole bunch of copying removed for brevity...

copying examples/pixelarray.py -> build/lib.macosx-10.9-x86_64-3.8/pygame/examples
copying examples/dropevent.py -> build/lib.macosx-10.9-x86_64-3.8/pygame/examples
running build_ext
building 'pygame.gfxdraw' extension
creating build/temp.macosx-10.9-x86_64-3.8
creating build/temp.macosx-10.9-x86_64-3.8/src_c
creating build/temp.macosx-10.9-x86_64-3.8/src_c/SDL_gfx
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DENABLE_NEWBUF=1 -I/NEED_INC_PATH_FIX -I/Library/Frameworks/Python.framework/Versions/3.8/include/python3.8 -c src_c/gfxdraw.c -o build/temp.macosx-10.9-x86_64-3.8/src_c/gfxdraw.o
In file included from src_c/gfxdraw.c:33:
In file included from src_c/pygame.h:32:
src_c/_pygame.h:216:10: fatal error: 'SDL.h' file not found
#include <SDL.h>
         ^~~~~~~
1 error generated.
---
For help with compilation see:
    https://www.pygame.org/wiki/MacCompile
To contribute to pygame development see:
    https://www.pygame.org/contribute.html
---
error: command 'gcc' failed with exit status 1
ERROR: Command errored out with exit status 1: 
   /Library/Frameworks/Python.framework/Versions/3.8/bin/python3 -u -c 'import sys, 
   setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install- 
   mtm_fm2t/pygame/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install- 
  mtm_fm2t/pygame/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/tmp/pip-record-vrvsxslr/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.

当我在 finder 中搜索时,文件 SDL.h确实存在,所以我不知道为什么这个安装失败。

我尝试了以下方法来解决这个问题,但没有成功。

  1. 使用 pip3 install pygame 安装
  2. 使用 pip3 install pygame--2.0.0_dev4 选项安装
  3. 我什至尝试下载 SDL2 源代码并进行编译。

它们都失败了(SDL make 长期失败,并在 lzma.h 周围出现错误

有没有人在 macOS 和 Python 3.7.4 上运行过 pygame,并且可以提供详细说明和先决条件的列表。

我只是在同样的问题上苦苦挣扎,终于能够通过使用以下命令行在带有 Mojave 的 Mac 上安装 pygame:

pip3 install pygame --only-binary :all:

这将安装 pygame 的预编译版本,从而避免丢失头文件(如错误消息中的 SDL.h)的问题,这是因为 pip 试图从在/usr/include中查找这些头文件的源代码编译 pygame . 随着 Mojave 和 Catalina 的最新更新,Apple 不再有/usr/include目录。 我确实检查了使用--only-binary选项安装的 pygame 版本,发现它是 2.0.0 开发版本,但到目前为止它似乎可以工作。

我能够通过使用easy_install pygame而不是 pip 来解决这个问题。 我怀疑它与python 3.8有关。

我在 macOS Catalina 上安装 pygame 时遇到了很多困难。 我尝试创建虚拟环境以及许多其他选项,但没有任何效果对我有用。 默认的python位于/usr/bin/python而我安装的python3位于/Library/Frameworks/Python.framework/Versions/3.8/bin/python3所以我没有使用pip install pygame ,而是尝试了easy_install-3.8 pygame它对我/Library/Frameworks/Python.framework/Versions/3.8 ,当我在/Library/Frameworks/Python.framework/Versions/3.8位置打开 bin 文件夹时,它有一个 easy_install-3.8 文件。 我对它了解不多,但我认为它与python3.8有关

暂无
暂无

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

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