`pygame`:在Ubuntu上,使用`pygame.image.save`来保存PNG导致`pygame.error:SavePNG:无法创建png write struct`

时间:2015-11-29 18:24:49

标签: python ubuntu pygame libpng

错误:

  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警告:使用libpng-1.2.51构建的应用程序,但以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测试应该是独立于平台的,但仍然失败?)。

1 个答案:

答案 0 :(得分:0)

此问题是由于I installed my Python stack using Anaconda引起的,但后来是installed pygame using the build+install instructions for Ubuntu on pygame's documentation page

这导致libpng的{​​{1}}库存在冲突,我认为,某处,某种程度上。

无论如何,这个问题已经解决了:

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

对于这个问题,我对此感到满意。

相关问题