Home>

I'm trying to make a simple game in Python

In the vc code, enter "import pgzrun" at the beginning, close the end with "pgzrun.go()" to create a file, and when you execute it, the following message appears.
I got the following error message.

Error message

File "/Users/my name/Downloads/import pgzrun.py", line 1, in
import pgzrun
ModuleNotFoundError: No module named'pgzrun'

Applicable source code
Source code


import pgzrun

WIDTH = 800

HEIGHT = 600

def draw():

screen.clear()

screen.draw.circle((400, 300), 30,'white')

pgzrun.go()```

What I tried

In the terminal, pgzero Pygame python 3.8.4 is installed with the current version.

There is the following guide on a certain pygame zero site↓
"But you can run python from IDEs like IDLE and Edublocks, but you can't run pgzrun.

Pygame Zero also uses python and provides a way to run it as an ordinary Python program. To do so, first add the following line at the beginning of your program:

Please state what you have tried for the problem here.

I could not do it with IDLE, so I downloaded the vc code and entered import pgzrun at the beginning, but it was useless.

Supplementary information (FW/tool ​​version, etc.)

Please provide more detailed information here.

  • Answer # 1

    File "/Users/my name/Downloads/import pgzrun.py", line 1, in

    Is the code written in the file name?

    If possible, make sure the filename does not contain spaces.
    It is not the cause of this error directly, but it leads to other problems.

    Temporarily file namemy_program.pySave as

    First, check the operation at the terminal,
    python my_program.pyPlease run as.
    pythonFor the part of, use the thing of the environment where the library is installed according to the environment.

    ModuleNotFoundError: No module named'pgzrun'
    In the terminal, pgzero Pygame python 3.8.4 is installed with the current version.

    (Confirmation)
    Where do you install
    How did you verify that it was installed?

    If you have a ModuleNotFoundError and it's installed, from the IDE
    Python of the environment where the library is not installed is used.

    Confirmation procedure:

    Let's check where pgzero was installed

    After checking the Python version,

    At the terminalpython -c "import pgzrun"

    If it is IDLE etc., go to the interactive modeimport pygrunPlease try typing.

    * Pgzrun is a module whose usage is special,
    It is supposed to be imported from within a Python file,
    If not, raise ImportError.

    What I want to check here is whether pgzrun is installed.
    The expected behavior is to get an ImportError (in the interactive environment).
    If the module cannot be found, you will get a ModuleNotFoundError.

    Workaround:

    You should be able to switch environments with VS code.

    For IDLE, open the IDLE of the environment where the library is installed
    python -m idlelibStart IDLE with


    I could not do it with IDLE, so I downloaded the vc code and entered import pgzrun at the beginning, but it was useless.

    This is a guide for executing with IDE (IDLE or VS Code).

    Details:
    The code for PyGame Zero ispgzrunBecause it is executed by command
    If you want to run it in the IDE, you need to set the runtime commands appropriately.

    aboveimport pgzrunWhenpgzrun.go()I mean,
    Script using PyGame ZeropythonThis is the correspondence method when executing with a command.