Has anyone gotten Pyglet to work

  • Thread starter Devyn Collier Johnson
  • Start date
D

Devyn Collier Johnson

I tried Pyglet in a Python3 and a Python2 script, but both fail. The
error code is below and the script is attached. The 'boot.ogg' file is
Ubuntu's default bootup sound. I got my code from this link
(http://guzalexander.com/2012/08/17/playing-a-sound-with-python.html).

collier@Nacho-Laptop:~$ ./pyglet.py
Traceback (most recent call last):
File "./pyglet.py", line 2, in <module>
import pyglet
File "/home/collier/pyglet.py", line 3, in <module>
song = pyglet.media.load('./boot.ogg')
AttributeError: 'module' object has no attribute 'media'


Mahalo,

DCJ
 
S

Steven D'Aprano

collier@Nacho-Laptop:~$ ./pyglet.py

Here you are running a module called pyglet, which I assume you wrote.

Traceback (most recent call last):
File "./pyglet.py", line 2, in <module>
import pyglet

And here you try to import the third-party module called pyglet, except
it is shadowed by your module, and you get your own module instead.
File "/home/collier/pyglet.py", line 3, in <module>
song = pyglet.media.load('./boot.ogg')
AttributeError: 'module' object has no attribute 'media'

Since your module has no attribute 'media', that error is correct.



The lesson here is, never name your own files the same as library files.
Unfortunately, that's easier said than done. I think everyone has made
the same mistake at least once in their life as a Python programmer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top