How can I get python3.4 to find the PySDL2 module I downloaded on win7?
Question: I downloaded pySDL2 (from <https://bitbucket.org/marcusva/py-sdl2/downloads>)
and unzipped the SDL2 package to my folder C:\Python34\Lib\site-
packages\PySDL2-0.9.3, which has a subfolder sdl2 which has a subfolder ext.

I also copied a 'hello world' program to the same folder, using the header:

    
    
    import os
    os.environ["PYSDL2_DLL_PATH"] = "/Python34/Lib/site-packages/PySDL2-0.9.3"
    import sys
    import sdl2.ext
    

I ran it from the same folder, and It said it couldn't find sdl2. (I used the
os.environ line, since I had already 'set' the environment variable, but it
didn't help)

ImportError: could not find any library for SDL2 (PYSDL2_DLL_PATH:
/Python34/Lib /site-packages/PySDL2-0.9.3/sdl2)

So I ran pip install PySDL2, and that said: C:\Python34\Lib\site-
packages\PySDL2-0.9.3>pip install pysdl2 Requirement already satisfied (use
--upgrade to upgrade): pysdl2 in c:\python34\ lib\site-packages Cleaning up...

So, I have the package in the python library, I have it pointed to in the
environment, and pip says its already there, but somehow python can't find it
to import.

What should I be doing?


Answer: PySDL2 doesn't come with the SDL2 libraries.

You need the SDL2 libraries for PySDL2 to work. SDL2 is the library that does
all the hard work. PySDL2 is just the interface to allow you to access it from
Python.

Have a look at <http://pysdl2.readthedocs.org/en/latest/install.html> for
details about how to install it. And then look at
<http://pysdl2.readthedocs.org/en/latest/integration.html> for information
about how to use PYSDL2_DLL_PATH

For my projects I chose not to install PySDL2 in Python at all. I put all the
PySDL2 stuff in a project subdirectory called "sdl2", and all the Windows SDL2
DLLs in a separate subdirectory called "sdl2_dll". Then in the root directory
of the project I have the following file called 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
    

Then, in each file that needs pysdl2, use `from sdlimport import *`

