3 Steps How to convert .py to .exe

I. how to change .py to .exe. (In no problem case)

  1. Install pyinstaller with command “pip install pyinstaller”
  2. “pyinstaller.exe” will located in …/Scripts/
  3. With command “pyinstaller — onefile …/yourfile.py”, it will generate .exe which located in …/Scripts/dist

II. ModuleNotFoundError: No module named ‘pandas._libs.tslibs.timedeltas’

It has a problem with pandas. The solution is create ‘hook-pandas.py’ and write the content as error you got, for example,

hiddenimports = [‘pandas._libs.tslibs.timedeltas’,
‘pandas._libs.tslibs.nattype’,
‘pandas._libs.tslibs.np_datetime’,
‘pandas._libs.skiplist’]

This file located in c:/~/Python3.6/Lib/site-package/PyInstaller/hooks

This method no need to change anything in .spec file.

Then, type the following command on the cmd to make a standalone application
pyinstaller -F — noconsole [filename]

or pyinstaller -F my_app.py

III. Got “No module named…”

First of all, you have check your environment that already contain the library. If the environment don’t have, you should install it by “pip install …”. Then re-built .exe file again, but if the problem is not fix, consider the IV method.

IV. pyinstaller + sklearn +scipy “No module named…”

To resolve this problem in easy way, we can have a modify in .spec file as following example:

Then, run command “pyinstaller file.spec”.

Read this article from the medium website: https://medium.com/@ascomlab.space/3-steps-convert-py-to-exe-e9ccd64a502