简体   繁体   中英

Can't import pygame even though it is installed

I go into IDLE and type in import pygame to the shell and it gives me an error. Then I go into a new program and type in import pygame and I get the same error. I installed pygame with pip and are using python 3, version 3.6.8.

I have tried reinstalling pygame and trying to install in with sudo. I also have tried using pip3, same result.

[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license()" for more information.
>>> import pygame
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import pygame
ModuleNotFoundError: No module named 'pygame'
>>> 

If you have pip installed, inside the terminal you should be doing:

pip install pygame

Also, make sure you actually have pip installed.. https://www.makeuseof.com/tag/install-pip-for-python/ Hope that helps, if it works, please mark my question as the answer. Good luck with your py-games. Welcome to the community!

Turns out I had to use 'pip3' and not just 'pip'. Thanks to everybody who helped.

Use pip3 pygame instead of pip pygame as on some systems with both python 2 and python 3, pip points to python 2's install, whereas pip3 points to python 3.

You can confirm this using

$ ls -l `which pip`
$ ls -l `which pip3`

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