我如何让pygame在解释器中运行?

问题描述 投票:0回答:1

我正在使用Mac和Catalina 10.15.2。我最近使用Pyenv安装了Python 3.7.3。我的翻译是Komodo Edit 12。我已经通过运行以下命令安装了pygame:pip3 install pygame

我的问题是Pygame。每当我尝试执行时:

#!/usr/bin/env python3

import pygame

Komodo返回:

Traceback (most recent call last):
  File "/Users/wetherman/Desktop/RandomPy/game.py", line 3, in <module>
    import pygame
ModuleNotFoundError: No module named 'pygame'

我认为,不寻常的部分是,当我在终端中键入python3,然后再键入import pygame时,它似乎可以正常工作。但是,当我从/usr/bin/启动Python Unix Executable时,我得到的错误与我在Komodo中获得的错误相同。

python pygame python-module
1个回答
0
投票

尝试安装pygame:

import subprocess
import os

try:
    subprocess.call([sys.executable, '-m', 'pip', 'install', 'pygame'])
    import pygame
    print('Pygame installed.')

except ModuleNotFoundError:
    try:
        subprocess.run('pip install pygame', shell = True)
        import pygame
        print('Pygame installed.')

    except ModuleNotFoundError:
        print('Pygame could not be installed.')
© www.soinside.com 2019 - 2024. All rights reserved.