gpt4 book ai didi

eclipse - 安装 pySDL2 后 SDL2 的运行时错误

转载 作者:太空宇宙 更新时间:2023-11-03 16:53:07 25 4
gpt4 key购买 nike

我通过以下方式安装了 pySDL2 0.4.1:

下载源码包,输入 python setup.py install。然后我尝试运行复制粘贴到 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 上可用 download page (Linux 除外)。

然后您应该通过设置 PYSDL2_DLL_PATH 让 PySDL2 位于库所在的位置,如下所示:

# 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

或在 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 编码愉快!

关于eclipse - 安装 pySDL2 后 SDL2 的运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18161509/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com