Python sdl2无效路径
我正在测试pysdl2的“学会飞行”教程。(我也是python新手) 我发现一个错误,认为这只是路径问题 错误:Python sdl2无效路径,python,pysdl2,Python,Pysdl2,我正在测试pysdl2的“学会飞行”教程。(我也是python新手) 我发现一个错误,认为这只是路径问题 错误: guillaume@ubuntu:~/script$ python sdlTest.py Traceback (most recent call last): File "sdlTest.py", line 4, in <module> RESOURCES = sdl2.ext.Resources(__file__, "resources") File
guillaume@ubuntu:~/script$ python sdlTest.py
Traceback (most recent call last):
File "sdlTest.py", line 4, in <module>
RESOURCES = sdl2.ext.Resources(__file__, "resources")
File "/usr/lib/python2.7/dist-packages/sdl2/ext/resources.py", line 139, in __init__
self.scan(path, subdir, excludepattern)
File "/usr/lib/python2.7/dist-packages/sdl2/ext/resources.py", line 313, in scan
raise ValueError("invalid path '%s'" % path)
ValueError: invalid path 'sdlTest.py'
我在ubuntu 16.04上
已安装的python版本
guillaume@ubuntu:~/script$ python -V
Python 2.7.12
python-sdl2版本:
guillaume@ubuntu:~/script$ dpkg -s python-sdl2
Package: python-sdl2
Status: install ok installed
Priority: optional
Section: python
Installed-Size: 392
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: all
Source: pysdl2
Version: 0.9.3+dfsg2-1
Depends: python:any (<< 2.8), python:any (>= 2.7.5-5~), libsdl2-2.0-0, libsdl2-gfx-1.0-0, libsdl2-image-2.0-0, libsdl2-mixer-2.0-0, libsdl2-ttf-2.0-0
Recommends: python-numpy
Suggests: pysdl2-doc
Description: Python bindings to the SDL2 C-library (Python 2 build)
PySDL2 is a ctypes based wrapper around the Simple DirectMedia Layer 2 library
to allow portable low level access to a video framebuffer, audio output, mouse
and keyboard.
.
This module is built for Python version 2.x.
Original-Maintainer: Debian Python Modules Team <python-modules-team@lists.alioth.debian.org>
Homepage: https://bitbucket.org/marcusva/py-sdl2
您可能未能在项目目录中包含资源文件夹 这个错误有点含糊不清,但这为我修复了它。“资源”指运行sdl2 python脚本的子目录的名称 在上的sdl2示例中,他们需要一个名为“resource”的目录来加载图像,这些图像将在随后的示例中显示在sdl2窗口中 我们需要资源文件夹中的一些资源,以便 测试周围的图像,以便稍后在窗口上显示。你自己 应用程序,您不太可能需要导入它们, 但是我们在这里需要它们,所以我们使用sdl2.ext.Resources类 它们是可用的 如果要继续使用该行:
RESOURCES = sdl2.ext.Resources(__file__, "resources")
然后从使用此行运行脚本的目录中,创建一个名为“resources”的子目录并运行脚本。您将看到错误消息不会出现。您可以使用“资源”以外的名称,只需确保存在同名的子目录
更重要的是,要使用sdl2,您只需要以下两行代码来加载sdl2模块,就可以了
import sdl2
import sdl2.ext
RESOURCES = sdl2.ext.Resources(__file__, "resources")
import sdl2
import sdl2.ext