So I have a script that prints the dominant colour of an image using PIL, numpy and scipy:
from PIL import Image
import numpy as np
import scipy.cluster
def dominant_color(image):
NUM_CLUSTERS = 5
image = image.resize((150, 150)) # optional, to reduce time
ar = np.asarray(image)
shape = ar.shape
ar = ar.reshape(np.product(shape[:2]), shape[2]).astype(float)
codes, dist = scipy.cluster.vq.kmeans(ar, NUM_CLUSTERS)
vecs, dist = scipy.cluster.vq.vq(ar, codes) # assign codes
counts, bins = np.histogram(vecs, len(codes)) # count occurrences
index_max = np.argmax(counts) # find most frequent
color = tuple([int(code) for code in codes[index_max]])
return color
image = Image.open("image.jpg")
print(dominant_color(image))
I create an exe using pyinstaller using the command pyinstaller --onefile --hidden-import=scipy test.py
But even with hidden import when I run the exe I get ModuleNotFoundError: No module named 'scipy'
I have also tried adding scipy.cluster
as a hidden import but I still get the same error. Am I missing a hidden import here?