我下载了pySDL2 (从https://bitbucket.org/marcusva/py-sdl2/downloads下载),并将SDL2包解压到我的文件夹C:\Python34LIB\site-packages\PySDL2-0.9.3,其中有一个子文件夹sdl2,其中有一个子文件夹ext。
我还使用头文件将一个'hello world‘程序复制到同一个文件夹中:
import os
os.environ["PYSDL2_DLL_PATH"] = "/Python34/Lib/site-packages/PySDL2-0.9.3"
import sys
import sdl2.ext我在同一个文件夹中运行了它,它说找不到sdl2。(我使用了os.environ行,因为我已经‘设置’了环境变量,但它没有帮助)
ImportError:找不到SDL2的任何库(PYSDL2_DLL_PATH: /Python34/Lib /site-packages/PySDL2-0.9.3/sdl2)
所以我运行了pip install PySDL2,并说: C:\Python34\Lib\site-packages\PySDL2-0.9.3>pip安装包要求已经满足(使用-- pysdl2来升级):pysdl2 in c:\python34\ lib\site-packages Cleaning up...
所以,我在python库中有这个包,我在环境中指向它,pip说它已经在那里了,但不知何故,python找不到它来导入。
我应该做些什么?
发布于 2015-11-04 03:58:36
SDL2库中没有附带PySDL2。
要使PySDL2正常工作,您需要SDL2库。SDL2是完成所有繁重工作的库。PySDL2只是一个允许您从Python访问它的接口。
有关如何安装它的详细信息,请查看http://pysdl2.readthedocs.org/en/latest/install.html。然后查看http://pysdl2.readthedocs.org/en/latest/integration.html以获取有关如何使用PYSDL2_DLL_PATH的信息
对于我的项目,我选择根本不用Python语言安装PySDL2。我将所有的PySDL2内容放在一个名为" SDL2“的项目子目录中,将所有的Windows SDL2 DLL放在一个单独的子目录"sdl2_dll”中。然后,在项目的根目录中,我有一个名为sdlimport.py的文件
"""Imports PySDL2 
This module imports PySDL2 and the SDL2 libraries held within the project
structure (i.e. not installed in Python or in the system).
Setup:
    [myproject]
     |-sdlimport.py
     |-main.py
     |-[sdl2]
     |  |-The PySDL2 files
     |-[sdl2_dll]
        |-SDL2.dll
        |-SDL2_image.dll
        |-SDL2_mixer.dll
        |-SDL2_ttf.dll
        |-and all the other dlls needed
    Edit sdlimport.py to include which bits of sdl2 you need.
Example:
    from sdlimport import *
    sdl2.dostuff()
"""
import os
# app_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")
app_dir = os.path.dirname(os.path.realpath(__file__))
"""str:  the path to your project, detected at import time
"""
sdl2_dll_path = os.path.join(app_dir, "sdl2_dll")
os.environ["PYSDL2_DLL_PATH"] = sdl2_dll_path
#--- Comment these out as needed ---
import sdl2
import sdl2.sdlimage
import sdl2.sdlttf
#import sdl2.sdlgfx 
#import sdl2.sdlmixer 
import sdl2.ext然后,在每个需要pysdl2的文件中,使用from sdlimport import *
发布于 2016-02-22 05:28:03
在我的系统上,我必须这样做才能让它知道sdl2在哪里(在我下载sdl2之后,pysdl2已经安装好了)。
导入操作系统
os.environ"PYSDL2_DLL_PATH“=r”c:\您的目录“
导入sdl2.ext
我尝试过的任何其他方式都不会起作用。只需切换到sdl2.dll所在的目录。
https://stackoverflow.com/questions/31174070
复制相似问题