Pygame 和 cx_freeze:分段错误
我正在使用 ubuntu 和 python 2.6
我发现 cx freeze 已经安装在我的系统上(有没有办法检查它是否与我的 Python 版本兼容?)
但是,我有一个小的 pygame 脚本(它导入另一个模块和一些图像) )并且我想编译它;
我将此文件用作 setup.py:
#!/usr/bin/python
from cx_Freeze import setup, Executable
setup(
name = 'Example',
version = '0.1',
description='hi',
executables = [Executable('/home/antonio/Python 26 save/opt/example.py')]
)
如果我运行生成的可执行文件(通过终端),我会收到此错误:
Fatal Python error: (pygame parachute) Segmentation Fault
Aborted
我应该做什么?我已经搜索过,但发现的例子很少,而且我在谷歌结果上没有看到这个错误
ps 当然,在使用 cx freeze 之前程序运行得很好
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我使用 python 2.7 也遇到了类似的问题。我在自己的程序中发现了导致此分段错误的两个原因,但我只有其中之一的解决方案。
原因1.初始化没有路径的字体,即调用:
这种情况下,valgrind报告在地址0x0处读取无效???在 pygame.font.so 中,
我猜测这是因为 None 被转换为 NULL 指针,然后假定该指针是有效的 const char* 字符串。
此问题的解决方法是始终提供字体的有效路径。
原因 2. 在字体中渲染 unicode 字符
valgrind 报告 libpython2.7.so.1.0 中的 PyString_AsString 读取无效
很抱歉,我对此没有解决方案。
附:
我刚刚发现了 cxfreeze 问题的另一个与 unicode 相关(但与 pygame 无关)的原因。
在 python 解释器中将打印一个国王(棋子),但是当使用 cxfreeze 编译脚本时,我收到以下错误(不是分段错误):
如果您调用,您也会在 python 解释器中收到此错误:
这似乎表明 cxfreeze 假设字符串始终为 ascii 字符串。
I have been getting a similar problem using python 2.7. I've found two causes of this segmentation fault in my own program, but I only have a solution to one of them.
Cause 1. Initialising fonts with no path, ie calling:
In this case, valgrind reports an invalid read at the address 0x0 in ??? in
pygame.font.so
I would guess that this is because None is converted to a NULL pointer which something then assumes is a valid const char* string.
The fix for this problem is to always supply a valid path to a font.
Cause 2. Rendering unicode characters in fonts
valgrind reports an invalid read in PyString_AsString in libpython2.7.so.1.0
I'm sorry to say I don't have a solution for this.
PS:
I have just found another unicode related (but not pygame related) cause of problems with cxfreeze.
In the python interpreter will print a king (chess piece), but when the script is compiled with cxfreeze, I get the following error (not a segmentation fault):
You also get this error in the python interpreter if you call:
This seems to indicate that cxfreeze is assuming strings are always ascii strings.
冻结脚本时是否设置了任何优化选项?我不太确定它是否会这样做,但可能是它错误地将变量更改为引用。再说一次,我不是 cx_freeze 的专家,但我的解决方案是更新。你有最新版本的(cx_freeze)吗?
Do you have any optimization options set when freezing the script? I'm not too sure if it does this, but it may be that it's incorrectly changing a variable to a reference. Again, I'm not an expert at cx_freeze, but my solution would be to update. Do you have the latest version (of cx_freeze)?
您是否在谷歌上搜索了您的错误(http://www.google.com/search?&q=Fatal%20Python%20error%3A%20%28pygame%20parachute%29%20Segmentation%20Fault)并检查了报告该错误的各种帖子同样的错误?
例如
Did you google for your error (http://www.google.com/search?&q=Fatal%20Python%20error%3A%20%28pygame%20parachute%29%20Segmentation%20Fault) and check the various posts reporting the same error ?
E.g.
我一直收到类似的错误,我想我已经找到了解决方案。
我正在使用
But 而不是传递 None 参数,您应该使用系统的字体。
我使用的是 Windows 机器,所以我没有用我的系统拥有的任何字体替换任何字体。所以我将其替换为:
如您所见,我已将 None 替换为 comicsansms,这是 Windows PC 上预装的字体
希望它有效!
I have been getting the similar error and I think I have found the solution.
I am using
But instead of passing None argument you should use your system's fonts.
I have using windows machine so I have replaced none with any font that my system has. So I have replaced it to:
As you can see I have replaced None with comicsansms which is preinstalled fonts on windows PC
Hope it works!
使用
pygame.font.SysFont(FONT_NAME, FONT_SIZE)
。Use
pygame.font.SysFont(FONT_NAME, FONT_SIZE)
.