Python:出现语法错误。可能是由于PIL库安装不正确

时间:2016-04-17 23:35:18

标签: python image python-3.x syntax-error python-imaging-library

width, height = img.size
total = 0
for row in range(width):
    for col in range(height):
        # This will save the RGBA values of the pixel
        red, green, blue, alpha = img.getpixel( (row, col) )
        new_red = red + new_red
        new_green = green + new_green
        new_blue = blue + new_blue
        total = 1 + total

average_red = new_red/total
average_green = new_green/total
average_blue = new_blue/total
img.putpixel((row, col,), (average_red, average_green, average_blue, 255)
img.show()

我在使用它时遇到语法错误。我猜这可能是由于PIL模块的安装不正确。

是否有人知道是否是这种情况?

如果是这样,是否有人可以指导我如何在Mac OSX中安装它?

1 个答案:

答案 0 :(得分:1)

你在

结尾处遗漏了)
img.putpixel((row, col), (average_red, average_green, average_blue, 255)

应该是

img.putpixel((row, col), (average_red, average_green, average_blue, 255))