Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while import pygame

I've installed pygame with Anaconda using the following command:
conda install --channel https://conda.anaconda.org/kne pygame

Then I tried to import pygame and I got the following error:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/ejalaa/anaconda/lib/python2.7/site-packages/pygame/__init__.py", line 133, in <module>
from pygame.base import *
ImportError: dlopen(/Users/ejalaa/anaconda/lib/python2.7/site-packages/pygame/base.so, 2): Library not loaded: /usr/local/opt/sdl/lib/libSDL-1.2.0.dylib
Referenced from: /Users/ejalaa/anaconda/lib/python2.7/site-packages/pygame/base.so
Reason: image not found

What does that mean ? Any idea how I can solve it?

Thank you.

like image 877
ejalaa12 Avatar asked Dec 16 '15 14:12

ejalaa12


People also ask

Why can I not import pygame?

The Python "ModuleNotFoundError: No module named 'pygame'" occurs when we forget to install the pygame module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install pygame command.

How do I import pygame?

Open a terminal, and type 'sudo apt-get install idle pygame', enter your password and type 'y' at the prompts, if necessary. 2. After the installation completes, enter 'python' in the terminal to launch Python. Verify that it's using version 2.7 or newer, then at the Python prompt enter 'import pygame'.

Does python 3.7 support pygame?

Because the PyGame is only supported python 3.7. 7 or higher version so make sure you are using the latest version of python.


1 Answers

A. Check if you have a 64 or 32 bit version pygame and make sure your version of python is the same.

B. Use something like pip install or any other type of method to install pygame.

C. Install a previous version of pygame and python, you might have some more luck with that.

The error is basically saying that a class in pygame called image could not be found. Obviously pygame has not been installed properly so I would suggest using the above methods to install it again.

I hope this helps!

like image 116
ModoUnreal Avatar answered Oct 06 '22 23:10

ModoUnreal