for event in pygame.event.get(): pygame.error: video system not initialized when using ssh










0















Here is the code that I'm trying to run via ssh into my raspberry pi. It usually works fine when I have a keyboard and monitor connected directly to the raspberry pi, but it doesn't run when I am using ssh.



import pygame, sys, time
from pygame.locals import *

pygame.init()
pygame.joystick.init()
joystick = pygame.joystick.Joystick(0)
joystick.init()
#screen = pygame.display.set_mode((400,300))
#pygame.display.set_caption('Hello World')

interval = 0.01

# get count of joysticks=1, axes=27, buttons=19 for DualShock 3

joystick_count = pygame.joystick.get_count()
print("joystick_count")
print(joystick_count)
print("--------------")

numaxes = joystick.get_numaxes()
print("numaxes")
print(numaxes)
print("--------------")

numbuttons = joystick.get_numbuttons()
print("numbuttons")
print(numbuttons)
wprint("--------------")

loopQuit = False
while loopQuit == False:

# test joystick axes
# outstr = ""
# for i in range(0,4):
# axis = joystick.get_axis(i)
# outstr = outstr + str(i) + ":" + str(axis) + "|"
# print(outstr)

# test controller buttons
outstr = ""
for i in range(0,numbuttons):
button = joystick.get_button(i)
outstr = outstr + str(i) + ":" + str(button) + "|"
print(outstr)

for event in pygame.event.get():
if event.type == QUIT:
loopQuit = True
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
loopQuit = True


The error that I am getting is
Traceback (most recent call last):
File "testing_joystick.py", line 47, in
for event in pygame.event.get():
pygame.error: video system not initialized



Can anyone help me figure out how to get around this error please?










share|improve this question




























    0















    Here is the code that I'm trying to run via ssh into my raspberry pi. It usually works fine when I have a keyboard and monitor connected directly to the raspberry pi, but it doesn't run when I am using ssh.



    import pygame, sys, time
    from pygame.locals import *

    pygame.init()
    pygame.joystick.init()
    joystick = pygame.joystick.Joystick(0)
    joystick.init()
    #screen = pygame.display.set_mode((400,300))
    #pygame.display.set_caption('Hello World')

    interval = 0.01

    # get count of joysticks=1, axes=27, buttons=19 for DualShock 3

    joystick_count = pygame.joystick.get_count()
    print("joystick_count")
    print(joystick_count)
    print("--------------")

    numaxes = joystick.get_numaxes()
    print("numaxes")
    print(numaxes)
    print("--------------")

    numbuttons = joystick.get_numbuttons()
    print("numbuttons")
    print(numbuttons)
    wprint("--------------")

    loopQuit = False
    while loopQuit == False:

    # test joystick axes
    # outstr = ""
    # for i in range(0,4):
    # axis = joystick.get_axis(i)
    # outstr = outstr + str(i) + ":" + str(axis) + "|"
    # print(outstr)

    # test controller buttons
    outstr = ""
    for i in range(0,numbuttons):
    button = joystick.get_button(i)
    outstr = outstr + str(i) + ":" + str(button) + "|"
    print(outstr)

    for event in pygame.event.get():
    if event.type == QUIT:
    loopQuit = True
    elif event.type == pygame.KEYDOWN:
    if event.key == pygame.K_ESCAPE:
    loopQuit = True


    The error that I am getting is
    Traceback (most recent call last):
    File "testing_joystick.py", line 47, in
    for event in pygame.event.get():
    pygame.error: video system not initialized



    Can anyone help me figure out how to get around this error please?










    share|improve this question


























      0












      0








      0








      Here is the code that I'm trying to run via ssh into my raspberry pi. It usually works fine when I have a keyboard and monitor connected directly to the raspberry pi, but it doesn't run when I am using ssh.



      import pygame, sys, time
      from pygame.locals import *

      pygame.init()
      pygame.joystick.init()
      joystick = pygame.joystick.Joystick(0)
      joystick.init()
      #screen = pygame.display.set_mode((400,300))
      #pygame.display.set_caption('Hello World')

      interval = 0.01

      # get count of joysticks=1, axes=27, buttons=19 for DualShock 3

      joystick_count = pygame.joystick.get_count()
      print("joystick_count")
      print(joystick_count)
      print("--------------")

      numaxes = joystick.get_numaxes()
      print("numaxes")
      print(numaxes)
      print("--------------")

      numbuttons = joystick.get_numbuttons()
      print("numbuttons")
      print(numbuttons)
      wprint("--------------")

      loopQuit = False
      while loopQuit == False:

      # test joystick axes
      # outstr = ""
      # for i in range(0,4):
      # axis = joystick.get_axis(i)
      # outstr = outstr + str(i) + ":" + str(axis) + "|"
      # print(outstr)

      # test controller buttons
      outstr = ""
      for i in range(0,numbuttons):
      button = joystick.get_button(i)
      outstr = outstr + str(i) + ":" + str(button) + "|"
      print(outstr)

      for event in pygame.event.get():
      if event.type == QUIT:
      loopQuit = True
      elif event.type == pygame.KEYDOWN:
      if event.key == pygame.K_ESCAPE:
      loopQuit = True


      The error that I am getting is
      Traceback (most recent call last):
      File "testing_joystick.py", line 47, in
      for event in pygame.event.get():
      pygame.error: video system not initialized



      Can anyone help me figure out how to get around this error please?










      share|improve this question
















      Here is the code that I'm trying to run via ssh into my raspberry pi. It usually works fine when I have a keyboard and monitor connected directly to the raspberry pi, but it doesn't run when I am using ssh.



      import pygame, sys, time
      from pygame.locals import *

      pygame.init()
      pygame.joystick.init()
      joystick = pygame.joystick.Joystick(0)
      joystick.init()
      #screen = pygame.display.set_mode((400,300))
      #pygame.display.set_caption('Hello World')

      interval = 0.01

      # get count of joysticks=1, axes=27, buttons=19 for DualShock 3

      joystick_count = pygame.joystick.get_count()
      print("joystick_count")
      print(joystick_count)
      print("--------------")

      numaxes = joystick.get_numaxes()
      print("numaxes")
      print(numaxes)
      print("--------------")

      numbuttons = joystick.get_numbuttons()
      print("numbuttons")
      print(numbuttons)
      wprint("--------------")

      loopQuit = False
      while loopQuit == False:

      # test joystick axes
      # outstr = ""
      # for i in range(0,4):
      # axis = joystick.get_axis(i)
      # outstr = outstr + str(i) + ":" + str(axis) + "|"
      # print(outstr)

      # test controller buttons
      outstr = ""
      for i in range(0,numbuttons):
      button = joystick.get_button(i)
      outstr = outstr + str(i) + ":" + str(button) + "|"
      print(outstr)

      for event in pygame.event.get():
      if event.type == QUIT:
      loopQuit = True
      elif event.type == pygame.KEYDOWN:
      if event.key == pygame.K_ESCAPE:
      loopQuit = True


      The error that I am getting is
      Traceback (most recent call last):
      File "testing_joystick.py", line 47, in
      for event in pygame.event.get():
      pygame.error: video system not initialized



      Can anyone help me figure out how to get around this error please?







      python joystick






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 9 '16 at 7:21







      Windell

















      asked Aug 7 '16 at 10:30









      WindellWindell

      11




      11






















          3 Answers
          3






          active

          oldest

          votes


















          0














          Well you have not initialized your window yet. It looks like you may or may not have commented it out: #screen = pygame.display.set_mode((400, 300)). Many of pygame's events rely on the window. Simply un-comment your screen initialization and it should work fine.






          share|improve this answer























          • I found out that it works fine when I have the monitor and keyboard connected directly to the Pi. But doesn't work via ssh. My program doesn't use the screen at all at this point so I commented it out because I still got the same error when it was I commented. Do I need to do anything special if my terminal is via ssh into the Pi?

            – Windell
            Aug 8 '16 at 0:48











          • What do you mean by the pi?

            – Christian Dean
            Aug 8 '16 at 1:42











          • My apologies, by Pi I meant raspberry Pi

            – Windell
            Aug 9 '16 at 6:29











          • You have your key-board and monitor connected to a raspberry pi? Do you mean a robot, a computer, or something else?

            – Christian Dean
            Aug 9 '16 at 6:32











          • A raspberry Pi is a single board computer capable of hdmi video, keyboard and mouse input via usb. It is about the size of a deck of cards. It also has an Ethernet port for network access. It runs a flavor of Debian Linux.

            – Windell
            Aug 9 '16 at 7:25


















          0














          I know it's been a while since the question has been posted, but I faced the same problem today.



          For me the sudo command resolved the ssh problem.



          sudo python code_path.py





          share|improve this answer






























            0














            I had a similar issue as described. The problem appears when no X server is available, that's why it works when you have a monitor connected to the Raspberry.



            A solution is to run ssh with the X forwarding option:



             ssh -X pi@raspberry_ip_address


            Then your program should run as normal:



             python your_code.py


            Hope this helps anybody else.






            share|improve this answer






















              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38813215%2ffor-event-in-pygame-event-get-pygame-error-video-system-not-initialized-when%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              Well you have not initialized your window yet. It looks like you may or may not have commented it out: #screen = pygame.display.set_mode((400, 300)). Many of pygame's events rely on the window. Simply un-comment your screen initialization and it should work fine.






              share|improve this answer























              • I found out that it works fine when I have the monitor and keyboard connected directly to the Pi. But doesn't work via ssh. My program doesn't use the screen at all at this point so I commented it out because I still got the same error when it was I commented. Do I need to do anything special if my terminal is via ssh into the Pi?

                – Windell
                Aug 8 '16 at 0:48











              • What do you mean by the pi?

                – Christian Dean
                Aug 8 '16 at 1:42











              • My apologies, by Pi I meant raspberry Pi

                – Windell
                Aug 9 '16 at 6:29











              • You have your key-board and monitor connected to a raspberry pi? Do you mean a robot, a computer, or something else?

                – Christian Dean
                Aug 9 '16 at 6:32











              • A raspberry Pi is a single board computer capable of hdmi video, keyboard and mouse input via usb. It is about the size of a deck of cards. It also has an Ethernet port for network access. It runs a flavor of Debian Linux.

                – Windell
                Aug 9 '16 at 7:25















              0














              Well you have not initialized your window yet. It looks like you may or may not have commented it out: #screen = pygame.display.set_mode((400, 300)). Many of pygame's events rely on the window. Simply un-comment your screen initialization and it should work fine.






              share|improve this answer























              • I found out that it works fine when I have the monitor and keyboard connected directly to the Pi. But doesn't work via ssh. My program doesn't use the screen at all at this point so I commented it out because I still got the same error when it was I commented. Do I need to do anything special if my terminal is via ssh into the Pi?

                – Windell
                Aug 8 '16 at 0:48











              • What do you mean by the pi?

                – Christian Dean
                Aug 8 '16 at 1:42











              • My apologies, by Pi I meant raspberry Pi

                – Windell
                Aug 9 '16 at 6:29











              • You have your key-board and monitor connected to a raspberry pi? Do you mean a robot, a computer, or something else?

                – Christian Dean
                Aug 9 '16 at 6:32











              • A raspberry Pi is a single board computer capable of hdmi video, keyboard and mouse input via usb. It is about the size of a deck of cards. It also has an Ethernet port for network access. It runs a flavor of Debian Linux.

                – Windell
                Aug 9 '16 at 7:25













              0












              0








              0







              Well you have not initialized your window yet. It looks like you may or may not have commented it out: #screen = pygame.display.set_mode((400, 300)). Many of pygame's events rely on the window. Simply un-comment your screen initialization and it should work fine.






              share|improve this answer













              Well you have not initialized your window yet. It looks like you may or may not have commented it out: #screen = pygame.display.set_mode((400, 300)). Many of pygame's events rely on the window. Simply un-comment your screen initialization and it should work fine.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Aug 7 '16 at 14:00









              Christian DeanChristian Dean

              15.7k52859




              15.7k52859












              • I found out that it works fine when I have the monitor and keyboard connected directly to the Pi. But doesn't work via ssh. My program doesn't use the screen at all at this point so I commented it out because I still got the same error when it was I commented. Do I need to do anything special if my terminal is via ssh into the Pi?

                – Windell
                Aug 8 '16 at 0:48











              • What do you mean by the pi?

                – Christian Dean
                Aug 8 '16 at 1:42











              • My apologies, by Pi I meant raspberry Pi

                – Windell
                Aug 9 '16 at 6:29











              • You have your key-board and monitor connected to a raspberry pi? Do you mean a robot, a computer, or something else?

                – Christian Dean
                Aug 9 '16 at 6:32











              • A raspberry Pi is a single board computer capable of hdmi video, keyboard and mouse input via usb. It is about the size of a deck of cards. It also has an Ethernet port for network access. It runs a flavor of Debian Linux.

                – Windell
                Aug 9 '16 at 7:25

















              • I found out that it works fine when I have the monitor and keyboard connected directly to the Pi. But doesn't work via ssh. My program doesn't use the screen at all at this point so I commented it out because I still got the same error when it was I commented. Do I need to do anything special if my terminal is via ssh into the Pi?

                – Windell
                Aug 8 '16 at 0:48











              • What do you mean by the pi?

                – Christian Dean
                Aug 8 '16 at 1:42











              • My apologies, by Pi I meant raspberry Pi

                – Windell
                Aug 9 '16 at 6:29











              • You have your key-board and monitor connected to a raspberry pi? Do you mean a robot, a computer, or something else?

                – Christian Dean
                Aug 9 '16 at 6:32











              • A raspberry Pi is a single board computer capable of hdmi video, keyboard and mouse input via usb. It is about the size of a deck of cards. It also has an Ethernet port for network access. It runs a flavor of Debian Linux.

                – Windell
                Aug 9 '16 at 7:25
















              I found out that it works fine when I have the monitor and keyboard connected directly to the Pi. But doesn't work via ssh. My program doesn't use the screen at all at this point so I commented it out because I still got the same error when it was I commented. Do I need to do anything special if my terminal is via ssh into the Pi?

              – Windell
              Aug 8 '16 at 0:48





              I found out that it works fine when I have the monitor and keyboard connected directly to the Pi. But doesn't work via ssh. My program doesn't use the screen at all at this point so I commented it out because I still got the same error when it was I commented. Do I need to do anything special if my terminal is via ssh into the Pi?

              – Windell
              Aug 8 '16 at 0:48













              What do you mean by the pi?

              – Christian Dean
              Aug 8 '16 at 1:42





              What do you mean by the pi?

              – Christian Dean
              Aug 8 '16 at 1:42













              My apologies, by Pi I meant raspberry Pi

              – Windell
              Aug 9 '16 at 6:29





              My apologies, by Pi I meant raspberry Pi

              – Windell
              Aug 9 '16 at 6:29













              You have your key-board and monitor connected to a raspberry pi? Do you mean a robot, a computer, or something else?

              – Christian Dean
              Aug 9 '16 at 6:32





              You have your key-board and monitor connected to a raspberry pi? Do you mean a robot, a computer, or something else?

              – Christian Dean
              Aug 9 '16 at 6:32













              A raspberry Pi is a single board computer capable of hdmi video, keyboard and mouse input via usb. It is about the size of a deck of cards. It also has an Ethernet port for network access. It runs a flavor of Debian Linux.

              – Windell
              Aug 9 '16 at 7:25





              A raspberry Pi is a single board computer capable of hdmi video, keyboard and mouse input via usb. It is about the size of a deck of cards. It also has an Ethernet port for network access. It runs a flavor of Debian Linux.

              – Windell
              Aug 9 '16 at 7:25













              0














              I know it's been a while since the question has been posted, but I faced the same problem today.



              For me the sudo command resolved the ssh problem.



              sudo python code_path.py





              share|improve this answer



























                0














                I know it's been a while since the question has been posted, but I faced the same problem today.



                For me the sudo command resolved the ssh problem.



                sudo python code_path.py





                share|improve this answer

























                  0












                  0








                  0







                  I know it's been a while since the question has been posted, but I faced the same problem today.



                  For me the sudo command resolved the ssh problem.



                  sudo python code_path.py





                  share|improve this answer













                  I know it's been a while since the question has been posted, but I faced the same problem today.



                  For me the sudo command resolved the ssh problem.



                  sudo python code_path.py






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 13 '18 at 6:00









                  feanfean

                  3213931




                  3213931





















                      0














                      I had a similar issue as described. The problem appears when no X server is available, that's why it works when you have a monitor connected to the Raspberry.



                      A solution is to run ssh with the X forwarding option:



                       ssh -X pi@raspberry_ip_address


                      Then your program should run as normal:



                       python your_code.py


                      Hope this helps anybody else.






                      share|improve this answer



























                        0














                        I had a similar issue as described. The problem appears when no X server is available, that's why it works when you have a monitor connected to the Raspberry.



                        A solution is to run ssh with the X forwarding option:



                         ssh -X pi@raspberry_ip_address


                        Then your program should run as normal:



                         python your_code.py


                        Hope this helps anybody else.






                        share|improve this answer

























                          0












                          0








                          0







                          I had a similar issue as described. The problem appears when no X server is available, that's why it works when you have a monitor connected to the Raspberry.



                          A solution is to run ssh with the X forwarding option:



                           ssh -X pi@raspberry_ip_address


                          Then your program should run as normal:



                           python your_code.py


                          Hope this helps anybody else.






                          share|improve this answer













                          I had a similar issue as described. The problem appears when no X server is available, that's why it works when you have a monitor connected to the Raspberry.



                          A solution is to run ssh with the X forwarding option:



                           ssh -X pi@raspberry_ip_address


                          Then your program should run as normal:



                           python your_code.py


                          Hope this helps anybody else.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 29 at 16:53









                          CappeCappe

                          11




                          11



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38813215%2ffor-event-in-pygame-event-get-pygame-error-video-system-not-initialized-when%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

                              How do I collapse sections of code in Visual Studio Code for Windows?

                              ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ