Why Do I get an ImportError when building a .exe with pyinstaller?

Chris picture Chris · Aug 2, 2015 · Viewed 9.3k times · Source

I just created a small GUI program that compiles and works fine in IPython, but when I try to export it to a .exe using pyinstaller it gives me an import error. I'm sure it's sklearn because when I comment out the sklearn imports my file open fine when I build it.

C:\Users\Chris\Anaconda>C:/Users/Chris/Anaconda/dist/Room_Test.exe
WARNING: file already exists but should not:                            C:\Users\Chris\AppData\Local\Temp\_MEI100402\Include\pyconfig.h
Traceback (most recent call last):
File "<string>", line 9, in <module>
File "C:\Users\Chris\Anaconda\Lib\site-    packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
  File "C:\Users\Chris\Anaconda\build\Room_Test\out00-    PYZ.pyz\sklearn.neighbors", line 6, in <module>
  File "C:\Users\Chris\Anaconda\Lib\site-    packages\PyInstaller\loader\pyi_importers.py", line 409, in load_module
    module = imp.load_module(fullname, fp, filename, self._c_ext_tuple)
  File "dist_metrics.pxd", line 48, in init sklearn.neighbors.ball_tree     (sklearn\neighbors\ball_tree.c:35726)
  File "C:\Users\Chris\Anaconda\Lib\site-    packages\PyInstaller\loader\pyi_importers.py", line 409, in load_module
    module = imp.load_module(fullname, fp, filename, self._c_ext_tuple)
  File "dist_metrics.pyx", line 52, in init sklearn.neighbors.dist_metrics     (sklearn\neighbors\dist_metrics.c:25494)
ImportError: No module named typedefs

Answer

Raissel Ramirez Orozco picture Raissel Ramirez Orozco · Aug 25, 2016

You can still use pyinstaller by adding the following to your command:

--hidden-import sklearn.neighbors.typedefs

or by adding the following to your .spec file:

hiddenimports=['cython', 'sklearn', 'sklearn.neighbors.typedefs']