gpt4 book ai didi

python - `pygame` : on Ubuntu, 使用 `pygame.image.save` 保存 PNG 导致 `pygame.error: SavePNG: could not create png write struct`

转载 作者:行者123 更新时间:2023-12-04 18:46:43 28 4
gpt4 key购买 nike

错误:

  File "/home/alien/cncell/core/animator.py", line 413, in create_animation_from_data
pygame.image.save(screen, image_fp)
pygame.error: SavePNG: could not create png write struct

可能的提示 A: 我现在在 Ubuntu 上。在 Windows 上运行相同的脚本时我没有这个问题。

可能的提示 B: 当第一次调用 pygame.image.save 时, libpng 会产生以下警告:

libpng warning: Application built with libpng-1.2.51 but running with 1.6.17



我应该怎么做才能解决这个问题?

我尝试过的一些事情:

1) 我可以加载PNG吗?

2) python -m pygame.tests 结果:
======================================================================
FAIL: BaseModuleTest.test_get_error
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/brian/anaconda2/lib/python2.7/site-packages/pygame/tests/base_test.py", line 569, in test_get_error
e)
AssertionError: Failed to access the SoundFont /usr/share/sounds/sf2/FluidR3_GM.sf2

======================================================================
FAIL: BaseModuleTest.test_set_error
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/brian/anaconda2/lib/python2.7/site-packages/pygame/tests/base_test.py", line 586, in test_set_error
e)
AssertionError: Failed to access the SoundFont /usr/share/sounds/sf2/FluidR3_GM.sf2

======================================================================
ERROR: GL_ImageSave.test_image_save_works_with_opengl_surfaces
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/brian/anaconda2/lib/python2.7/site-packages/pygame/tests/image__save_gl_surface_test.py", line 37, in test_image_save_works_with_opengl_surfaces
pygame.image.save(screen, tmp_file)
error: SavePNG: could not create png write struct

======================================================================
ERROR: ImageModuleTest.testSavePNG24
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/brian/anaconda2/lib/python2.7/site-packages/pygame/tests/image_test.py", line 215, in testSavePNG24
pygame.image.save(surf, f_path)
error: SavePNG: could not create png write struct

======================================================================
ERROR: ImageModuleTest.testSavePNG32
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/brian/anaconda2/lib/python2.7/site-packages/pygame/tests/image_test.py", line 184, in testSavePNG32
pygame.image.save(surf, f_path)
error: SavePNG: could not create png write struct

======================================================================
ERROR: ImageModuleTest.test_save
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/brian/anaconda2/lib/python2.7/site-packages/pygame/tests/image_test.py", line 248, in test_save
pygame.image.save(s, temp_filename)
error: SavePNG: could not create png write struct

======================================================================
ERROR: ImageModuleTest.test_save_colorkey
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/brian/anaconda2/lib/python2.7/site-packages/pygame/tests/image_test.py", line 275, in test_save_colorkey
pygame.image.save(s, temp_filename)
error: SavePNG: could not create png write struct

======================================================================
ERROR: ImageextModuleTest.test_save_unicode_path
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/brian/anaconda2/lib/python2.7/site-packages/pygame/tests/imageext_test.py", line 65, in test_save_unicode_path
imageext.save_extended(im, temp_file)
error: SavePNG: could not create png write struct

----------------------------------------------------------------------
Ran 708 tests in 28.894s

FAILED (failures=2, errors=6)

这些测试的结果让我认为这个问题不太可能是由于将我的代码从 Windows 移植到 Ubuntu 所特有的问题(例如,我尽可能地尝试修复路径名等,并且 pygame 测试应该是平台独立的,但仍然失败?)。

最佳答案

这个问题是因为 I installed my Python stack using Anaconda , 但后来 installed pygame using the build+install instructions for Ubuntu on pygame 's documentation page .

这导致 libpng 的库发生冲突。 ,我想,某处,不知何故。

无论如何,该问题已通过以下方式解决:

1) 删除 pygame(因为我使用了 pip 来安装 pygame,pip uninstall pygame 成功了)

2) 安装pygame using a build some kind soul had contributed to the conda repositories

然后,运行 python -m pygame.tests没有报告任何错误,除了:

======================================================================
FAIL: BaseModuleTest.test_get_error
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/brian/anaconda2/lib/python2.7/site-packages/pygame/tests/base_test.py", line 569, in test_get_error
e)
AssertionError: Failed to access the SoundFont /usr/share/sounds/sf2/FluidR3_GM.sf2

======================================================================
FAIL: BaseModuleTest.test_set_error
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/brian/anaconda2/lib/python2.7/site-packages/pygame/tests/base_test.py", line 586, in test_set_error
e)
AssertionError: Failed to access the SoundFont /usr/share/sounds/sf2/FluidR3_GM.sf2

出于这个问题的目的,我同意。

关于python - `pygame` : on Ubuntu, 使用 `pygame.image.save` 保存 PNG 导致 `pygame.error: SavePNG: could not create png write struct`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33986315/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com