Skip to main content
 首页 » 编程设计

python之使用绝对路径的 Pyglet 加载资源

2024年10月25日7itcoder

<分区>

我是 python 的新手,我对此进行了一些研究,但我找到的答案似乎不起作用。我试图用带有绝对路径的 pyglet 加载一个 mp3 文件,但它给出了这个错误:

Traceback (most recent call last): 
  File "C:\Apps\Python\lib\site-packages\pyglet\resource.py", line 624, in media 
    location = self._index[name] 
KeyError: 'C:/Users/Ruurd/Google Drive/Script/Python/music2.mp3' 
 
During handling of the above exception, another exception occurred: 
 
Traceback (most recent call last): 
  File "C:/Users/Ruurd/Desktop/playmus.py", line 3, in <module> 
    music=pyglet.resource.media(path) 
  File "C:\Apps\Python\lib\site-packages\pyglet\resource.py", line 634, in media 
    raise ResourceNotFoundException(name) 
pyglet.resource.ResourceNotFoundException: Resource "C:/Users/Ruurd/Google Drive/Script/Python/music2.mp3" was not found on the path.  Ensure that the filename has the correct captialisation. 

当我使用“music2.mp3”作为路径时,它工作正常。这是无效代码

import pyglet 
path='C:/Users/Ruurd/Google Drive/Script/Python/music2.mp3' 
music=pyglet.resource.media(path) 
music.play()