简体   繁体   中英

Pygame installed but won't import

A month ago I installed pygame and wrote a lot of working programs using it. Now I come to run those programs again and I get the error:

    Traceback (most recent call last):
      File "C:\Users\User\Desktop\Python\ESOL Games\Level 1.py", line 3, in <module>
        import pygame
    ModuleNotFoundError: No module named 'pygame'

I've used pip freeze:

C:\Users\User>pip3 freeze
beautifulsoup4==4.8.0
bs4==0.0.1
cycler==0.10.0
et-xmlfile==1.0.1
jdcal==1.4.1
kiwisolver==1.1.0
matplotlib==3.1.1
numpy==1.17.2
openpyxl==2.6.3
Pillow==6.1.0
pygame==1.9.6
pyparsing==2.4.2
python-dateutil==2.8.0
six==1.12.0
soupsieve==1.9.3

and tried to pip and got

C:\Users\User>python -m pip install pygame

Requirement already satisfied: pygame in 
c:\users\user\appdata\local\programs\python\python37\lib\site-packages (1.9.6)

So I fully believe pygame is installed, so why will it not import? I have not changed the directories of any of the previously working programs and I've not moved Idle either.

Why can't it find pygame module?

Can you check if you have more than one python installed on your system.

You can cross check by from command line type where python and in the python file running type the below code

import sys
sys.executable

check if both the pythons are same.

If not you should export the path of the python to which your pygame package is installed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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