3

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 
5
  • 2
    Could you post the full traceback verbatim? Commented Jun 4, 2017 at 3:57
  • may help: stackoverflow.com/questions/18033227/python-pyglet-and-opengl Commented Jun 4, 2017 at 4:06
  • PyLab - No, you don't need that to be interactive. I'm wondering what OS and version of Pyglet you got installed? Commented Jun 5, 2017 at 9:34
  • I added all that information to the question above Commented Jun 5, 2017 at 17:00
  • Make sure you haven't named any of your files the same thing as an important library module. Commented Jun 5, 2017 at 17:15

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.