我对pysdl2有问题。我正在尝试从site packages\sdl2\examples启动示例,并看到以下错误:
c:\Python33\Lib\site-packages\sdl2\examples>python draw.py
Traceback (most recent call last):
File "draw.py", line 10, in <module>
import sdl2.ext as sdl2ext
File "C:\Python33\lib\site-packages\sdl2\ext\__init__.py", line 14, in <module>
from .common import *
File "C:\Python33\lib\site-packages\sdl2\ext\common.py", line 8, in <module>
from .. import sdlttf
File "C:\Python33\lib\site-packages\sdl2\sdlttf.py", line 40, in <module>
os.getenv("PYSDL2_DLL_PATH"))
File "C:\Python33\lib\site-packages\sdl2\dll.py", line 51, in __init__
raise RuntimeError("could not find any library for %s" % libinfo)
RuntimeError: could not find any library for SDL2_ttf
但不使用sdl2_ttf(如sdl2hello.py)的文件工作正常,没有错误。我不知道怎么解决。
附加信息:winxp sp3 32位
最佳答案
此错误似乎是脚本找不到SDL2_ttf
包的结果。
在the instructions of the PySDL2 manual之后,您必须像这样设置aPYSDL2_DLL_PATH
:
# Win32 platforms
set PYSDL2_DLL_PATH=C:\path\to\fancy_project\third_party
# Unix/Posix-alike environments - bourne shells
export PYSDL2_DLL_PATH=/path/to/fancy_project/third_party
# Unix/Posix-alike environments - C shells
setenv PYSDL2_DLL_PATH /path/to/fancy_project/third_party
因此,您只需在这里获得
SDL2_ttf
包:http://www.libsdl.org/projects/SDL_ttf/并下载对应于您的系统的运行库(http://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.12-win32-x86.zip),并将其添加到相同的文件夹中。入住SDL2.dll
它与
C:\your-python-directory\DLLs
,SDL_image
,SDL_mixer
和SDL_net
(在另一个网站上,虽然最后一个)相同。希望这有帮助!