My python project works fine on my Ubuntu desktop, but not on my Raspberry Pi (under Raspbarian) despite having followed the same steps.
I have followed the instructions at https://pysdl2.readthedocs.io/en/rel_0_9_6/install.html, making sure SDL2 is installed using “sudo apt-get install libsdl2-dev”, and then downloading the PySDL2 archive and running “sudo python setup.py install”.
On the Raspberry Pi I get the following error:
File “/home/pi/Documents/tv/test2.py” line 3, in
import sdl2
ImportError: No module named 'sdl2’
Here is my code for test2.py, modified from the following link (I just added some VLC stuff) https://pysdl2.readthedocs.io/en/rel_0_9_6/modules/sdl2.html;
import sys
import ctypes
from sdl2 import *
#VLC stuff
import vlc
def main():
SDL_Init(SDL_INIT_VIDEO)
window = SDL_CreateWindow(b"Hello World",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
592, 460, SDL_WINDOW_SHOWN)
windowsurface = SDL_GetWindowSurface(window)
image = SDL_LoadBMP(b"exampleimage.bmp")
SDL_BlitSurface(image, None, windowsurface, None)
SDL_UpdateWindowSurface(window)
SDL_FreeSurface(image)
#VLC stuff
vlcInstance = vlc.Instance("--no-xlib")
player = vlcInstance.media_player_new()
#Xwindow ID stuff
wminfo = SDL_SysWMinfo();
SDL_GetVersion(wminfo.version);
if(SDL_GetWindowWMInfo(window, wminfo) == 0):
print("can't get SDL WM info");
sys.exit(1);
win_id = wminfo.info.x11.window;
player.set_xwindow(win_id)
player.set_mrl("agro.mp4")
player.play()
running = True
event = SDL_Event()
while running:
while SDL_PollEvent(ctypes.byref(event)) != 0:
if event.type == SDL_QUIT:
running = False
break
elif event.type == SDL_KEYDOWN:
if event.key.keysym.sym == SDLK_UP:
player.stop()
SDL_UpdateWindowSurface(window)
if event.key.keysym.sym == SDLK_DOWN:
player.play()
player.stop()
vlcInstance.release()
SDL_DestroyWindow(window)
SDL_Quit()
return 0
if __name__ == "__main__":
sys.exit(main())