我通过安装了pySDL2 0.4.1
下载源包,进入CCD_ 1。然后我尝试运行粘贴到PyDev eclipse"the Pong Game:Getting Started"教程中的代码示例:
导入操作系统,系统
try:
os.environ["PYSDL2_DLL_PATH"] = "/home/me/workspace/Pong/third-party"
print(os.getenv("PYSDL2_DLL_PATH"))
from sdl2 import events, SDL_QUIT
import sdl2.ext as sdl2ext
except ImportError:
import traceback
traceback.print_exc()
sys.exit(1)
def run():
sdl2ext.init()
window = sdl2ext.Window("The Pong Game", size=(800, 600))
window.show()
running = True
while running:
events = sdl2ext.get_events()
for event in events:
if event.type == SDL_QUIT:
running = False
break
window.refresh()
return 0
if __name__ == "__main__":
sys.exit(run())
我得到以下错误:
Traceback (most recent call last):
File "/home/me/workspace/Pong/Main.py", line 11, in <module>
from sdl2 import *
File "/usr/local/lib/python3.3/dist-packages/sdl2/__init__.py", line 2, in <module>
from .dll import get_dll_file, _bind
File "/usr/local/lib/python3.3/dist-packages/sdl2/dll.py", line 90, in <module>
dll = _DLL("SDL2", ["SDL2", "SDL2-2.0"], os.getenv("PYSDL2_DLL_PATH"))
File "/usr/local/lib/python3.3/dist-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
我已经通过Synaptic安装了Pypy和libSDL,并且在PyDev-PythonPath中没有添加外部库。
我做错了什么?
PySDL2似乎找不到SDL2
运行库。它们可以在libsdl下载页面上找到(linux除外)。
然后,您应该让PySDL2位于库所在的位置,方法是将PYSDL2_DLL_PATH
设置为:
# Win32 platforms
set PYSDL2_DLL_PATH=C:pathtofancy_projectthird_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
或者在python脚本中:
# Win32 Platform path
os.environ["PYSDL2_DLL_PATH"] = "C:\path\to\fancy_project\third_party"
# Unix/Posix-alike environments path
os.environ["PYSDL2_DLL_PATH"] = "/path/to/fancy_project/third_party"
这样,PySDL2将始终找到库文件(当然,只要路径正确)!在我看来,这是比较容易的方法。
SDL2编码快乐!
几乎解决了。Ubuntu有SDL1.2,SDL的主下载页面也指向SDL1.2。需要通过键入来安装源程序包
mkdir /opt/sdl2
cd /opt/sdl2
hg clone http://hg.libsdl.org/SDL SDL
cd SDL
mkdir build && cd build
../configure
make
sudo make install
然后从下载SDL_image-2.x.x.tar.gzhttp://www.libsdl.org/tmp/SDL_image/
和类型:
../configure
make
sudo make install
最后类型:
ldconfig /usr/local/lib
现在唯一不起作用的是SDL_QUIT没有被识别。