【问题标题】:`pygame`: on Ubuntu, using `pygame.image.save` to save PNG causes `pygame.error: SavePNG: could not create png write struct``pygame`:在 Ubuntu 上,使用 `pygame.image.save` 保存 PNG 会导致 `pygame.error: SavePNG: could not create png write struct`
【发布时间】:2016-03-03 08:43:34
【问题描述】:

错误:

  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 测试应该独立于平台,但仍然失败?)。

【问题讨论】:

    标签: python ubuntu pygame libpng


    【解决方案1】:

    这个问题是因为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) 安装pygameusing 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
    

    就这个问题而言,我同意。

    【讨论】:

      猜你喜欢
      • 2012-03-09
      • 1970-01-01
      • 1970-01-01
      • 2011-02-17
      • 2017-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多