Posted by José Lopes
It may happen, after using py2exe several times with different projects, that the exe files get an error but the equivalent python files run without problems when executed from a shell.
Your last project runs without any problem but an older one that you just changed gives you this problem.
Let us first glance to the way py2exe works in order to understand the problem.
py2exe stores all the projects necessary data in the build directory, including
the compiled python modules (files with the extension .pyc or .pyo).
If no reset is done to this directory (deleting all its content) between projects,
py2exe will keep accumulating data.
Now reusing code in Python is very common for a bunch of reasons quite obvious for those who use this language.
It's then also common to use the same files in different projects, files that may had suffer changes to fit the
needs.
In these cases you'll end up with several files with the same name between projects but with different contents.
Once you use py2exe in a situation like this you would expect some kind of internal conflict that would raise an error
or a warning. Well, it doesn't happens!
The way the data is accumulated makes that each time two python files are found with the same name,
py2exe considers the most recent file and overwrites the existing older one.
The solution is quite simple, you just reset the build directory by deleting all its content each time
you start a new project.
Don't worry, you can delete all its content anytime that when you run py2exe only the necessary modules will be included.