Error while import pygame

三世轮回 提交于 2021-01-21 07:30:15

问题


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.


回答1:


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!




回答2:


After wasting 2 hours, I realized the culprit is the "conda install" which caused the bad installation.

the solution is simply uninstall it and pip install it:

pip uninstall pygame pip install pygame




回答3:


Similar problem here.

My experience: Used conda install -c https://conda.anaconda.org/quasiben pygame to install 1.9.1.

Then conda uninstall pygame, and pip install pygame (This time 1.9.3, and it works)




回答4:


if you are using python 2.7, mac os and conda for package management. You should try this. (I only tested it for python 2.7, but similar approach should work for python 3.x as well)

[optional] if you don't create conda environment yet, you can create one as shown below. Let's assume your conda environment name 'conda-env-p27'

conda create -n conda-env-p27 python=2.7 anaconda

Activate your conda environment. Let's assume your conda environment name 'conda-env-p27'

source activate conda-env

[optional] if you already install pygame with conda, you must uninstall it.

conda uninstall pygame

Then, install pygame with pip package manager. ()

pip install pygame

I had installed pygame with prior to activate conda environment. But, It does not work. But, after activating conda environment, I have install it again with pip and it worked for me.



来源:https://stackoverflow.com/questions/34315144/error-while-import-pygame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!