For python 3.x version.
intall pyinstaller
$ pip install pyinstaller
then
$ pyinstaller --onefile helloworld.py
Above will compile the helloworld.py into an exe file, saved to /dist folder
Sometimes the exe doesn't work complaining about some library/package not found.
It could be sth to do with the setuptools. If it's too new e.g. setuptools 4.5 as at july 2020, it didn't work. But reversing back to setuptools 4.4 works.
$pip install setuptools==44.0.0
This is for python 2.x version.
1. download and install py2exe
2. go to the python source file folder, create a setup.py file as in below:
from distutils.core import setup
import py2exe
setup(console=['you python source file.py'])
3. from command line, run
python setup.py py2exe
4. done, everything is packaged into a /dist folder with the exe