Raspberry pi and Pygame Menu - python

I wanted to use a library in python called pygame-menu in raspberry pi because I wanted to develop a game with somebody else. I tested one of their demos and I got the following error:
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "/home/pi/Pandemic/GameDev.py", line 2, in <module>
import pygame_menu
File "/home/pi/.local/lib/python3.7/site-packages/pygame_menu/__init__.py", line 66, in <module>
import pygame_menu.themes
File "/home/pi/.local/lib/python3.7/site-packages/pygame_menu/themes.py", line 386, in <module>
THEME_DEFAULT = Theme()
File "/home/pi/.local/lib/python3.7/site-packages/pygame_menu/themes.py", line 198, in __init__
bool, pygame.vernum.major == 2) # type: bool
AttributeError: 'tuple' object has no attribute 'major'
Here is also my code:
import pygame
import pygame_menu
pygame.init()
surface = pygame.display.set_mode((600, 400))
def set_difficulty(value, difficulty):
# Do the job here !
pass
def start_the_game():
# Do the job here !
pass
menu = pygame_menu.Menu(300, 400, 'Welcome',
theme=pygame_menu.themes.THEME_SOLARIZED)
menu.add_text_input('Name :', default='John Doe')
menu.add_selector('Difficulty :', [('Hard', 1), ('Easy', 2)], onchange=set_difficulty)
menu.add_button('Play', start_the_game)
menu.add_button('Quit', pygame_menu.events.EXIT)
menu.mainloop(surface)
Can you please help me fix it I ran the program with Thonny

it seems that the error comes from the pygame_menu library. You should check the compatibility between pygame_menu and pygame version. The last version of pygame-menu require pygame 1.9.6 or more.

I have fixed it. It turns out the raspberry pi has a default version of 1.9.4 of pygame and pygame-menu required 1.9.6 and above so I upgraded it with this command:
python3 -m pip install -U pygame --user

Related

Missing OpenGL.GL model

I am trying to run this code:
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
But I get this error:
Traceback (most recent call last):
File "/Users/Abood/Documents/lol.py", line 3, in <module>
from OpenGL.GL import *
ModuleNotFoundError: No module named 'OpenGL.GL'
I tried removing the .GL part and this came up:
Traceback (most recent call last): File "/Users/Abood/Documents/lol.py", line 4, in <module> from OpenGL.GLU import * ModuleNotFoundError: No module named 'OpenGL.GLU'
You have to install both the pygame and OpenGL packages. The easiest way is using pip:
pip install pygame
pip install PyOpenGL
This worked for me. After installing the packages and running your code, I got:
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
There are also different ways to install the OpenGL module. See the installation instructions on the PyOpenGL website.

Turtle won't import on python3.5 fedora 23

I installed the tkinter packages from the fedora repo, then I ran a simple turtle code in python... A test one form a website. (with import turtle at the top)
I then tried running the following code:
from turtle import *
color('red', 'yellow')
begin_fill()
while True:
forward(200)
left(170)
if abs(pos()) < 1:
break
end_fill()
done()
And it got the following error
[max#localhost python]$ python3 test.py
Traceback (most recent call last):
File "test.py", line 1, in <module>
import turtle
ImportError: No module named 'turtle'
And now even when I run the original program it no longer works.
It gives the exact same error as the test.py program.
dnf install python3-tkinter.x86_64

Pygame installed, but not working

I am using a mac and i want to use pygame but it is not working.
this is the error i get when I try to do import pygame
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
import pygame
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py", line 95, in <module>
from pygame.base import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so, 2): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so: no matching architecture in universal wrapper
Please help I am using python 2.7.9
If your file name is called pygame.py the system imports your python file.
If your file name is not pygame.py, you can try doing pip install pygame or python -m install pygame.

Pygame not importing correctly

I'm new to Python, and I'm trying to get started with Pygame.
When I run this code:
import pygame
pygame.init()
I get this error:
Traceback (most recent call last):
File "C:\Users\Jason\PycharmProjects\Game\myapp.py", line 6, in <module>
pygame.init()
AttributeError: 'module' object has no attribute 'init'
But when I try to see if I accidentally imported another file:
import pygame
import inspect
# Initialize the game engine
print(inspect.getfile(pygame))
pygame.init()
I get this weird error:
Traceback (most recent call last):
File "C:\Users\Jason\PycharmProjects\Game\myapp.py", line 5, in <module>
print(inspect.getfile(pygame))
File "C:\Python34\lib\inspect.py", line 518, in getfile
raise TypeError('{!r} is a built-in module'.format(object))
TypeError: <module 'pygame' (namespace)> is a built-in module
How can I import the right Pygame?
I'm using 3.4 on Windows 7 and Pygame 1.9.2a0 (for 3.2) in C:/Python34.
Thank you
It all has to with the version. That simple.
The original answer was here: https://stackoverflow.com/a/23484831/2486953
I had to download the 64 bit version from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame
Thanks #BrenBarn for your help!

Pygame installation error

I have installed Python 3.4.0 on a Win Vista Home Premiun 32bit machine with "Service Pack 2" installed.
Python installed to C:\Python34
I then chose the pygame windows binary pygame-1.9.2a0.win32-py3.2 since this is the closest to Python 3.4.0.
When in the shell or via a .py file and I use from pygame import *, I get the following error:
*Traceback (most recent call last):
File "C:/Users/Stuart/Desktop/Python Project files/g.py", line 1, in <module>
from pygame import *
File "C:\Python34\lib\site-packages\pygame\__init__.py", line 95, in <module>
from pygame.base import *
ImportError: DLL load failed: The specified module could not be found.*
I found a pygame install for python 3.4 at http://www.lfd.uci.edu/~gohlke/pythonlibs/

Categories

Resources