After I installed cologram library, Pycharm showed me an import error. I installed Python3.9 on D:\Program Files\Python3\ and installed Pycharm on D:\Program Files\JetBrains. Here is the code and the screenshots:
import colorgram
rgb_colors = []
colors = colorgram.extract('img.jpg', 30)
for color in colors:
r = color.rgb.r
g = color.rgb.g
b = color.rgb.b
new_color = (r, g, b)
rgb_colors.append(new_color)
print(rgb_colors)
I also checked the suggested answer, but it didn't help me out.