Pygame 和 cx_freeze:分段错误

发布于 2024-11-02 02:01:10 字数 630 浏览 2 评论 0 原文

我正在使用 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 之前程序运行得很好

I'm using ubuntu and python 2.6

I found cx freeze already installed on my system (is it there a way to check if it's compatible with my Python version? )

however, i have a small pygame script (which import another module and some images) and i want to compile it;

i used this file as 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')]
    )

if i run the resulting executable, (through the terminal) i get this error:

Fatal Python error: (pygame parachute) Segmentation Fault
Aborted

what should i do? I've searched but I found very few examples and I didn't see this error on google results

ps of course the program was running perfectly before using cx freeze

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

暮凉 2024-11-09 02:01:10

我使用 python 2.7 也遇到了类似的问题。我在自己的程序中发现了导致此分段错误的两个原因,但我只有其中之一的解决方案。

原因1.初始化没有路径的字体,即调用:

pygame.font.Font(None, font_size)

这种情况下,valgrind报告在地址0x0处读取无效???在 pygame.font.so 中,

我猜测这是因为 None 被转换为 NULL 指针,然后假定该指针是有效的 const char* 字符串。

此问题的解决方法是始终提供字体的有效路径。

原因 2. 在字体中渲染 unicode 字符

pygame.font.Font("data/DejaVuSans.ttf", 14).render(u'\u2654')

valgrind 报告 libpython2.7.so.1.0 中的 PyString_AsString 读取无效

很抱歉,我对此没有解决方案。

附:
我刚刚发现了 cxfreeze 问题的另一个与 unicode 相关(但与 pygame 无关)的原因。

print u'\u2654'

在 python 解释器中将打印一个国王(棋子),但是当使用 cxfreeze 编译脚本时,我收到以下错误(不是分段错误):

UnicodeEncodeError: 'ascii' codec can't encode character u'\u2654' in position 0: ordinal not in range(128)

如果您调用,您也会在 python 解释器中收到此错误:

print str(u'\u2654')

这似乎表明 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:

pygame.font.Font(None, font_size)

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

pygame.font.Font("data/DejaVuSans.ttf", 14).render(u'\u2654')

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.

print u'\u2654'

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):

UnicodeEncodeError: 'ascii' codec can't encode character u'\u2654' in position 0: ordinal not in range(128)

You also get this error in the python interpreter if you call:

print str(u'\u2654')

This seems to indicate that cxfreeze is assuming strings are always ascii strings.

因为看清所以看轻 2024-11-09 02:01:10

冻结脚本时是否设置了任何优化选项?我不太确定它是否会这样做,但可能是它错误地将变量更改为引用。再说一次,我不是 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)?

皓月长歌 2024-11-09 02:01:10

您是否在谷歌上搜索了您的错误(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.

辞慾 2024-11-09 02:01:10

我一直收到类似的错误,我想我已经找到了解决方案。
我正在使用

pygame.font.SysFont(None,25)

But 而不是传递 None 参数,您应该使用系统的字体。
我使用的是 Windows 机器,所以我没有用我的系统拥有的任何字体替换任何字体。所以我将其替换为:

pygame.font.SysFont("comicsansms",25)

如您所见,我已将 None 替换为 comicsansms,这是 Windows PC 上预装的字体
希望它有效!

I have been getting the similar error and I think I have found the solution.
I am using

pygame.font.SysFont(None,25)

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:

pygame.font.SysFont("comicsansms",25)

As you can see I have replaced None with comicsansms which is preinstalled fonts on windows PC
Hope it works!

肥爪爪 2024-11-09 02:01:10

使用
pygame.font.SysFont(FONT_NAME, FONT_SIZE)

Use
pygame.font.SysFont(FONT_NAME, FONT_SIZE).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文