.py to .exe
  1. Install the auto-py-to-exe module using pip (it doesn't work?).
  2. Run python -m auto_py_to_exe in CMD (a graphic window shown below will open).
  3. Img
  4. Enter the .py file path. Select One File for the app to be standalone and Window Based (hide the console) if the app has a GUI. Choose the icon, if you have any.
  5. Click "Convert .py to .exe," wait, and press "Open output folder" to copy your app file(s).

Troubleshooting: External modules your app uses may contain "hidden imports," meaning they can depend on different modules that are not explicitly imported in your code. If your program does not open, compile it once again but without hiding the console, and when trying to run it, hold the CMD window with your mouse (so that it doesn't disappear) to see the error, which will probably be 'No module named ...'. Then, head back to the auto-py-to-exe GUI, add the missing module name in the --hidden-import field in the "Advanced" section, and try again.

For example, to convert an app using CustomTkinter to an .exe file, we need to include tkinter, distutils, ctypes.wintypes, and tkinter.ttk to --hidden-imports. We also have to add the customtkinter/ and darkdetect/ module folders from the directory with installed Python modules to Additional Files.