【问题标题】:Pip3 install pygame not workingPip3安装pygame不工作
【发布时间】:2018-08-10 19:45:49
【问题描述】:

我有一台运行 OS X 10.6 的 Macbook,我正在尝试使用 pip3 install pygame 安装 pygame。

使用 python 3.7 和 pip 18.0。

以下是来自控制台的错误。

Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/Z6/Z6RVS9IMHG4+tkl202dsTU+++TM/-Tmp-/pip-install-ftjsil2g/pygame/setup.py", line 609, in <module>
        setup(**PACKAGEDATA)
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools/__init__.py", line 129, in setup
        return distutils.core.setup(**attrs)
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools/command/install.py", line 61, in run
        return orig.install.run(self)
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/command/install.py", line 545, in run
        self.run_command('build')
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/command/build.py", line 135, in run
        self.run_command(cmd_name)
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools/command/build_ext.py", line 78, in run
        _build_ext.run(self)
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/command/build_ext.py", line 309, in run
        customize_compiler(self.compiler)
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/sysconfig.py", line 170, in customize_compiler
        _osx_support.customize_compiler(_config_vars)
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/_osx_support.py", line 418, in customize_compiler
        _find_appropriate_compiler(_config_vars)
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/_osx_support.py", line 191, in _find_appropriate_compiler
        "Cannot locate working compiler")
    SystemError: Cannot locate working compiler

Command "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3 -u -c "import setuptools, tokenize;__file__='/private/var/folders/Z6/Z6RVS9IMHG4+tkl202dsTU+++TM/-Tmp-/pip-install-ftjsil2g/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/var/folders/Z6/Z6RVS9IMHG4+tkl202dsTU+++TM/-Tmp-/pip-record-vgz3goci/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/Z6/Z6RVS9IMHG4+tkl202dsTU+++TM/-Tmp-/pip-install-ftjsil2g/pygame/

编辑:固定格式!

【问题讨论】:

  • 你安装了 Python3 和 pip3 吗? Mac OSX 仅附带 Python 2.7。
  • 我以为python3自带pip3
  • 有时不会,如果您使用安装程序从 python.org 进行安装,那么它会执行,但例如在 Linux 的命令行上,您有时还需要单独下载 pip。跨度>
  • 运行 python3 -vpip3 -v 来检查你的版本。也可能是你的 PATH 中没有 python3。
  • 您也可以格式化您的错误消息。只需选择它们并按ctrl+k。它们很难以当前格式阅读。

标签: installation pip pygame


【解决方案1】:

所以我不完全了解您的错误消息是怎么回事,但我建议您查看这篇文章,因为它很好地介绍了在 Mac OSX 10.6-10.9 上设置 Pygame。

http://brysonpayne.com/2015/01/10/setting-up-pygame-on-a-mac/

如果上述方法不起作用,请按照以下说明进行操作。


注意:我正在介绍每一步,所以请跳过你已经完成的那些

第 1 步:安装 Python 3 和 Pip

在此处下载 Python 3.7:Python 3.7.0

运行安装程序并确保选择 pip(我不记得这是否可选)。

第 2 步:安装 Pygame

运行以下命令使用 pip 安装 Pygame:

python3 -m pip install -U pygame --user

第 3 步:测试 Pygame 安装

运行此命令测试 Pygame 是否安装正确:

python3 -m pygame.examples.aliens

【讨论】:

  • 我无法获得 Xcode,因为我的操作系统太旧,而且我也无法获得自制软件。会发生这种情况: -e:1:表达式中的无效字符 \342' in expression -e:1: Invalid char \200' -e:1:表达式中的无效字符 `\234'
  • 当我尝试 python3 -m pip install -U pygame --user 它与我的问题中的错误相同
  • 这很奇怪,我只是在我自己的机器上完成了这些步骤,它对我有用。还要仔细检查一下,你的路径中有/Library/Frameworks/Python.framework/Versions/3.7/bin
  • 其实我没有所以就加了,还是不行
【解决方案2】:

目前,2020 年 5 月 1 日,您无法使用 pip install pygame 在 python 3.8 中安装 pygame 库,但您可以使用它们的特定版本安装它们,仍然适用于开发人员。

您可以使用此版本在命令行中安装 Python 3.8:

*pip install pygame==2.0.0.dev6*

最新版本:

*pip install pygame==2.0.0.dev10*

你可以检查一下 终端:

$ python3
>>import pygame
pygame 2.0.0.dev10 (SDL 2.0.12, python 3.8.2)
Hello from the pygame community. https://www.pygame.org/contribute.html

【讨论】:

    猜你喜欢
    • 2022-12-11
    • 2021-07-18
    • 1970-01-01
    • 1970-01-01
    • 2018-09-03
    • 1970-01-01
    • 2015-03-26
    • 2019-07-16
    • 1970-01-01
    相关资源
    最近更新 更多