【问题标题】:pygame installed in pycharm but still showing no module named pygamepygame 安装在 pycharm 中,但仍显示没有名为 pygame 的模块
【发布时间】:2020-07-20 23:35:37
【问题描述】:

我在 MacOS 上,尝试安装 pygame,但不断收到“No module named 'pygame'”错误。

从终端开始

$ python3 -m pip install pygame

报错:

command 'gcc' failed with exit status 1

一些答案​​表明 pygame 与我当前的 python 版本 3.8 不兼容。于是我安装了python3.7.7并成功安装了pygame。 1

运行测试

$ python3 -m pygame.tests

终端显示OK2

我尝试在 pycharm 和 IDLE 中运行 import pygram 的项目,都给了我错误:No module named 'pygame'

还尝试在 Pycharm 中将项目解释器更改为 python 3.7,并在 pycharm 中安装了 pygame。仍然得到同样的错误。 3

我不确定哪里出错了。感谢任何帮助!谢谢。

【问题讨论】:

  • 在pycharm终端里面,python --versionpython -m pip list | grep pygame的输出是什么
  • PyCharm 对新项目的默认行为是创建一个空的虚拟环境。通过 PyCharm 的设置 GUI,要么在虚拟环境中安装 pygame,要么将当前解释器更改为您的全局 Python 3.7.7。
  • @RMPR python 版本是 3.7.7。 pip list 返回 pip 19.0.3、pygame 1.9.6、setuptools 40.8.0

标签: python pygame pycharm


【解决方案1】:

既然您已经降级了您的 python 版本,gcc 错误不再显示了吗?

你可以试试这个:

pip install pygame==1.9.2 

另外,我不知道你是否检查过这个文档,但它很有帮助:https://www.pygame.org/wiki/MacCompile

【讨论】:

    猜你喜欢
    • 2020-06-22
    • 2020-10-01
    • 2021-01-13
    • 2020-11-27
    • 2021-11-01
    相关资源
    最近更新 更多