3 Steps convert .py to .exe

AIT LAB
AIT LAB
Sep 5, 2018 · 2 min read

*******************************************************************

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”.

AIT LAB

Written by

AIT LAB

Aerospace Information Technology Laboratory, IAAI, KMITL, Bangkok, Thailand

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade