问题
So I tried to install pySDL2 just now, but I keep getting an error stating:
No module named 'sdl2.util'
I've followed the directions from the website, so I have no idea why this is not working. And I don't see anyone else asking this.
1: I downloaded: "PySDL2-0.9.2.zip" from BitBucket.
2: I unzipped the folder and moved the contents out.
3: I went to my command line, and then navigated to the directory containing the setup.py
4: I typed (As directed in the instructions): python setup.py install
5: The installation seemed to have worked fine, and once the command line was returned to me, I closed it out.
6: Navigated to the Examples folder, and tried to run an example:
ImportError: No module named 'sdl2.util'
I then tried importing sdl2, which resulted in the same error. Can anyone tell me why I am getting these errors? Or what I may have done wrong? I don't know what else to provide as information. I really only followed the couple steps provided, and for some reason I can't seem to access SDL2 from python . .
[Update]
So the sdl2.util error has now been removed. I have installed the required DLL for SDL2 into the Python33's DLLs
Folder. I then attempted to set the environment variable for the DLL to it's location. (So that I would stop getting error's concerning a missing library, ect). This doesn't actually fix the problem though. The tutorial clearly states that this command should be run from the command line in order to solve my issue:
set PYSDL2_DLL_PATH=C:\path\to\fancy_project\third_party
I then modified this to point to the location of the DLL file:
set PYSDL2_DLL_PATH=C:\Python33\Dlls
All good right? Nope. For some reason, this just doesn't work. Every time I want to run an example, I need to continuously set the environment variable as such:
os.environ["PYSDL2_DLL_PATH"] = "C:\\Python33\DLLs"
If I don't include this, I get the following error:
RuntimeError: could not find any library for SDL2 (PYSDL2_DLL_PATH: unset)
It would appear that my environment variable is not set, but why this is the case I don't know. I have tried setting it several times and restarted once. Yet this persists. If anyone can assist it would be great.
回答1:
I first run the command: python setup.py build then: python setup.py install And download a dll file named SDL2.dll put it under the folder :C:\Windows\System32 It works for me to run the example code.Hope helps!
回答2:
Creating an Environment Variable for windows with the following parameters:
Variable Name: PYSDL2_DLL_PATH
Variable Value: PATH_TO_THE_DLL_FILE_LOCATION
Fixed the issue.
Using the Windows set
command is apparently only temporary.
来源:https://stackoverflow.com/questions/24441836/trouble-installing-pysdl2-on-windows-no-module-error