本文介绍了无法在Windows上安装PySDL2. (无模块错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我刚才尝试安装pySDL2,但是我不断收到错误消息:

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: 我从BitBucket下载了"PySDL2-0.9.2.zip".

2: 我解压缩了文件夹并将其内容移出.

3: 我转到命令行,然后导航到包含setup.py

4: 我输入了(按照说明): python setup.py install

5: 该安装似乎运行良好,一旦将命令行返回给我,我便将其关闭.

6: 定位到示例文件夹,并尝试运行示例:

6: Navigated to the Examples folder, and tried to run an example:

然后我尝试导入sdl2,这导致了相同的错误.谁能告诉我为什么我会收到这些错误?还是我做错了什么?我不知道还有什么可以提供的信息.我实际上只遵循了提供的几个步骤,由于某种原因,我似乎无法从python访问SDL2.

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 . .

[更新]

因此,现在已消除了sdl2.util错误.我已将SDL2所需的DLL安装到Python33的DLLs文件夹中.然后,我尝试将DLL的环境变量设置为其位置. (这样,我就不会再遇到有关缺少的库等的错误).但是,这实际上并不能解决问题.该教程明确指出,应从命令行运行此命令以解决我的问题:

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:

然后我将其修改为指向DLL文件的位置:

I then modified this to point to the location of the DLL file:

好吧?没有.由于某种原因,这是行不通的.每次我想运行一个示例时,都需要像这样连续设置环境变量:

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.

推荐答案

使用以下参数为Windows创建环境变量:

Creating an Environment Variable for windows with the following parameters:

变量名称: PYSDL2_DLL_PATH

Variable Name: PYSDL2_DLL_PATH

变量值: PATH_TO_THE_DLL_FILE_LOCATION

Variable Value: PATH_TO_THE_DLL_FILE_LOCATION

解决了该问题.

使用Windows set命令显然只是临时的.

Using the Windows set command is apparently only temporary.

这篇关于无法在Windows上安装PySDL2. (无模块错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 19:15