I have a program that creates a word cloud, I am trying to include the module wordcloud into the .exe using py2exe, however I have observed in the library.zip file in the dist folder that py2exe collects all .pyd and .pyc except those that do not have an extension file. In a sense the stopwords file of the wordcloud module cannot be packaged by py2exe but it is an essential file to execute the WordCloud().
My first approach was to rename the stopwords file into .txt, I rerun the code and it gives me an Errno2, it cant locate the stopwords.txt file. So i revert it back to its original form, the one without an extension.
My second approach was to include the soprword file to my_datafile in py2exe setup.py:
from distutils.core import setup
import py2exe,sys,os
import matplotlib
import wordcloud
import matplotlib.backends.backend_tkagg
sys.setrecursionlimit(5000)
Mydata_files =[('file', ['C:\\Python27\Lib\\site-packages\\wordcloud\\stopwords.*'])]
Mydata_files.extend(matplotlib.get_py2exe_datafiles())
setup(
console=['._ProbMod_.py'],
data_files = Mydata_files,
options={
'py2exe': {
'includes': ['sklearn.neighbors.typedefs','sklearn','sklearn.utils.sparsetools._graph_validation','sklearn.utils.validation','scipy.sparse.csgraph._validation','sklearn.utils.weight_vector','sklearn.utils.lgamma','FileDialog',
'scipy.special._ufuncs_cxx','scipy','matplotlib','pylab','FileDialog', 'scipy.integrate', 'scipy.special.*','scipy.linalg.*','matplotlib.backends.backend_tkagg']
}
}
)
the result is the same, Errno 2, it cant find the stopwords file in the library.zip file.
My third approach was to include the wordcloud module in the "include" function of py2exe:
from distutils.core import setup
import py2exe,sys,os
import matplotlib
import wordcloud
import matplotlib.backends.backend_tkagg
sys.setrecursionlimit(5000)
setup(
console=['._ProbMod_.py'],
data_files = matplotlib.get_py2exe_datafiles(),
options={
'py2exe': {
'includes': ['sklearn.neighbors.typedefs','sklearn','sklearn.utils.sparsetools._graph_validation','sklearn.utils.validation','scipy.sparse.csgraph._validation','sklearn.utils.weight_vector','sklearn.utils.lgamma','FileDialog',
'scipy.special._ufuncs_cxx','scipy','matplotlib','pylab','FileDialog', 'scipy.integrate', 'scipy.special.*','scipy.linalg.*','matplotlib.backends.backend_tkagg','wordcloud']
}
}
)
still Errno 2 persist.
Last approach was to manually copy the stopwords into the wordcloud folder in the library.zip file unfortunately, it didnt work too.
Does anyone knows how to tell py2exe to include all the files in a site-packages module folder and not just to package the .pyc and .pyd?
The solution was quite crude I re-edited my setup.py into:
This will make py2exe not to create the library.zip, then I manually copy-pasted all the required files into the wordcloud folder in the created dist folder.
It worked now.