Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NameError: global name 'EventLoop' is not defined - pyglet

I am trying to have python play an audio file for me. I am writing my code in enthought canopy.

import pyglet

sound = pyglet.media.load('song.wav')
sound.play()
pyglet.app.run()

When I run this I get an error: NameError: global name 'EventLoop' is not defined Also, the audio file plays the first note before the program errors.

I have no idea what is going on.

p.s. Do I need the pylab backend to be interactive for pyglet?

OS - osx 10.12.1 pyglet version 1.1.4-3

Traceback

NameError                                 Traceback (most recent call last)
/Users/name/Documents/name/Arduino Projects/python/Audio Testing.py in <module>()
      3 sound = pyglet.media.load('s.wav')
      4 sound.play()
----> 5 pyglet.app.run()

/Users/name/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pyglet/app/__init__.pyc in run()
    262 
    263     '''
--> 264     EventLoop().run()
    265 
    266 def exit():

NameError: global name 'EventLoop' is not defined 
like image 957
Sam Haberkorn Avatar asked Jun 08 '26 16:06

Sam Haberkorn


1 Answers

I tried to reproduce the error but was unable to, although this library seems like it has a few other bugs too.

I did find that using the latest version of the library worked much better. My suggestion is to bump your version from 1.1.4 to 1.2.4.

pip uninstall pyglet
pip install pyglet==1.2.4
like image 57
nichochar Avatar answered Jun 12 '26 01:06

nichochar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!