5

Using PyInstaller 3.3, Python 3.4 I have compiled a program that needs to use the scipy.signal.periodogram() function, and it's causing the .exe to crash the instant it starts up. I've been searching all over stack overflow and other sites for a way to try to include the right DLLs, but to no avail. Please help me figure out if I need to include some specific DLLs in my .spec file or include some other hidden-imports!

Here is my PyInstaller command:

pyinstaller --noupx --hidden-import=tkinter --hidden-import=scipy --hidden-import=matplotlib constantG_constantHz.py

and here is the corresponding error from the command prompt after starting my exe:

Traceback (most recent call last):

  File "constantG_constantHz.py", line 16, in <module>

  File "C:\Users\esandberg\AppData\Local\Continuum\anaconda3\envs\py34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
    exec(bytecode, module.__dict__)

  File "site-packages\scipy\signal\__init__.py", line 304, in <module>

  File "C:\Users\esandberg\AppData\Local\Continuum\anaconda3\envs\py34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
    exec(bytecode, module.__dict__)

  File "site-packages\scipy\signal\bsplines.py", line 12, in <module>

  File "C:\Users\esandberg\AppData\Local\Continuum\anaconda3\envs\py34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
    exec(bytecode, module.__dict__)

  File "site-packages\scipy\special\__init__.py", line 640, in <module>

  File "C:\Users\esandberg\AppData\Local\Continuum\anaconda3\envs\py34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 714, in load_module
    module = loader.load_module(fullname)

ImportError: DLL load failed: The specified module could not be found.

[1272] Failed to execute script constantG_constantHz

And here is my .spec file:

# -*- mode: python -*-

block_cipher = None


a = Analysis(['constantG_constantHz.py'],
             pathex=['C:\\Users\\esandberg\\Desktop'],
             binaries=[],
             datas=[],
             hiddenimports=['tkinter', 'scipy', 'matplotlib'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          name='constantG_constantHz',
          debug=False,
          strip=False,
          upx=False,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=False,
               name='constantG_constantHz')
RTbecard
  • 868
  • 1
  • 8
  • 23
Erik
  • 1,196
  • 2
  • 9
  • 18
  • Check my answer here, it isn't exactly the same, but might be of use https://stackoverflow.com/questions/46499068/pyinstaller-not-loading-dll/46679099#46679099 – The4thIceman Nov 01 '17 at 23:44
  • Additionally, are there any warnings that come up when you compile with pyinstaller? – The4thIceman Nov 01 '17 at 23:45
  • Yes, there a dozens of random warnings like "77227 WARNING: lib not found: libopenblas.BNVRK7633HSX7YVO2TADGR4A5KEKXJAW.gfortran-win_amd64.dll dependency of C:\Users\esandberg\AppData\Local\Continuum\anaconda3\envs\py34\lib\site-packages\scipy\linalg\_flapack.pyd" – Erik Nov 01 '17 at 23:50
  • Those warnings are indicative of the problem. Your code compiles, but it is warning you of missing things. Can you post your spec file? – The4thIceman Nov 01 '17 at 23:54
  • I just added it, take a look and see what you think. – Erik Nov 02 '17 at 15:00
  • I wasn't worried about most of the "missing" dlls for reasons like this (they just aren't an issue): https://stackoverflow.com/questions/17023419/win-7-64-bit-dll-problems?rq=1 My searching around the web seems to show a weird error with the scipy module specifically which is where my trouble is coming from – Erik Nov 02 '17 at 15:07
  • You need to run a dependency search on your exe to figure out the dependencies you are missing (likely the ones in the warnings). A "dll load failed" error means it can't find the dll you want (or any of the ones that it depends on). Use dumpin or dependencywalker to identify the missing ones. – The4thIceman Nov 02 '17 at 15:58
  • If there is an issue with scipy itself, then it is out of my realm of knowledge. Which operating system are you running? In you python code are you accessing an external dll anywhere? – The4thIceman Nov 02 '17 at 16:06
  • It turned out to be a combination of lots of missing dlls. PyInstaller and Scipy can work, but for some reason it has trouble finding most of scipy's dlls. I'll post my .spec file as an answer, and maybe anyone running into similar trouble will be able to try something similar for themselves. Thanks for helping me get to the bottom of it! – Erik Nov 03 '17 at 15:41

2 Answers2

4

I have tried the methods before and it did not solve my problem. Finally, I solved it by this way.

When compiling the executables (exe) files in the command (cmd) window, my command is written as follows:

pyinstaller -F --paths C:\Users\Desktop\Code\2018.04.23\venv\Lib\site-packages\scipy\extra-dll pdf_num_detect.py

Hope this small tricks can help you all.

Li Xibo
  • 41
  • 5
1

The issue was lots of missing dlls. PyInstaller has issues finding most of Scipy's dlls, so I had to specify a heck of a lot of them. I'll post my .spec file below in case anyone else wants to see / copy which dlls I had to bring in. Some things might not have been necessary, but it works so I'm not going to mess with it. Make sure that you are pointing to the correct directory for your system though - it won't be the same as mine, so don't just copy/paste :)

# -*- mode: python -*-

block_cipher = None

mkl_dlls =     [('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\numpy\\core\\mkl_avx.dll', '.'),
     ('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\numpy\\core\\mkl_avx2.dll', '.'),
     ('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\numpy\\core\\mkl_avx512.dll', '.'),
 ('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\numpy\\core\\mkl_core.dll', '.'),
 ('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\numpy\\core\\mkl_def.dll', '.'),
 ('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\numpy\\core\\mkl_intel_thread.dll', '.'),
 ('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\numpy\\core\\mkl_mc.dll', '.'),
 ('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\numpy\\core\\mkl_mc3.dll', '.'),
 ('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\numpy\\core\\mkl_rt.dll', '.'),
 ('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\numpy\\core\\mkl_sequential.dll', '.'),
 ('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\numpy\\core\\mkl_tbb_thread.dll', '.'),
 ('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\numpy\\core\\mkl_vml_avx.dll', '.'),
 ('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\numpy\\core\\mkl_vml_avx2.dll', '.'),
 ('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\numpy\\core\\mkl_vml_avx512.dll', '.'),
 ('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\numpy\\core\\mkl_vml_cmpt.dll', '.'),
 ('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\numpy\\core\\mkl_vml_def.dll', '.'),
 ('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\numpy\\core\\mkl_vml_mc.dll', '.'),
 ('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\numpy\\core\\mkl_vml_mc2.dll', '.'),
 ('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\numpy\\core\\mkl_vml_mc3.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\numpy\\core\\libiomp5md.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libansari.R6EA3HQP5KZ6TAXU4Y4ZVTRPT7UVA53Z.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libbanded5x.WZIUXDGQF4EXGFMCS2HGNLMUYHBRQUUF.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libbispeu.5N2XSD7URZS4WTOSLTOG4DDMA4HGB46U.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libblkdta00.LJOUU3SAGG47ULUG76DDJIAQ3SJZPC3K.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libchkder.6HLXPVTQJEGRZGLI5DFRMNW3SS76BHP6.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libcobyla2.JEGTSUUFJ7DFXWZN5PAYZTTLBDATC4WD.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libdcosqb.K4J3XBR4PEETMRHZICUWW4LXG5UONZ34.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libdcosqb.QRGA36MB6CFHWLQN6ETWARR4M4E6P3C2.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libdcsrch.I2AOPDCXAPDRFNPWY55H5UE7XZSU5CVN.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libdet.6GZFPKJ7BNDGVB7LFKBA6Z6U3VHYDRNY.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libdfft_sub.U4F67CR5EXPQGGTDKQXO4Q644NUQ3EQ6.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libdfitpack.2Y4SCYSHMU4DXJIF3BLBGBCDGFPGNXB5.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libdgamln.VNYWJHKRIIPRROV3CUDLW473BST7CGWP.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libdop853.6TJTQZW3I3Q3QIDQHEOBEZKJ3NYRXI4B.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libdqag.62LLADARAQRQLGIRWJXRQ7DKBCHYVFM7.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libd_odr.QDWMEQYLAGCKZEYTV3WWPRP5CLZ3G4WQ.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\liblbfgsb.T5BNFBSTQTIIF6ISVJFBJAWBU7OKBGPL.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libmvndst.LY22DRRGFBEFI34ZKZWNM3LQKXRWY2M2.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libnnls.5LTQOLAJY5PFO6MOEXWNMRWVFRWHYHKT.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libopenblas.BNVRK7633HSX7YVO2TADGR4A5KEKXJAW.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libslsqp_op.NNY57ZXZ43A4RH3YWFA7BKHP5PC2K3I5.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libspecfun.PT6DS3HUOGYNSXUO4OUKK6ATA7B5KP2K.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libSTOPTEST.ULMD4CATLBJOTE3KABHKOG56HAQIX5F6.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libvode.XW5WVKKTDJOOC5XUHCVKZ4AYR2TXGRF4.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libwrap_dum.G2F2CGV7KURTEF5GFBNVGKVM6FV5JBCV.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\libwrap_dum.XGSO5H22J6VUAWYNCLIXCV2EJ754HJMI.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\lib_arpack-.BSIUF6E2Z6VKRD6SNEY37WASTOLCKTAP.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\lib_blas_su.C3OGRVVRISPWLMOVEY4KXYSPKJEZ7QG6.gfortran-win_amd64.dll', '.'),
('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\envs\\py34\\Lib\\site-packages\\scipy\\extra-dll\\lib_test_fo.JF5HTWMUPBXWGAYEBVEJU3OZAHTSVKCT.gfortran-win_amd64.dll', '.')]

a = Analysis(['constantG_constantHz.py'],
         pathex=['C:\\Users\\esandberg\\Desktop'],
         binaries=mkl_dlls,
         datas=[('C:\\Users\\erik\\AppData\\Local\\Continuum\\anaconda3\\Lib\\site-packages\\scipy\\special\\_ufuncs_cxx.cp36-win_amd64.pyd','.'),],
         hiddenimports=['scipy._lib.messagestream', 'numpy', 'tkinter', 'scipy', 'matplotlib', 'fixtk', 'scipy.signal', 'scipy.signal.bsplines', 'scipy.special', 'scipy.special._ufuncs_cxx',
                        'scipy.linalg.cython_blas',
                        'scipy.linalg.cython_lapack',
                        'scipy.integrate',
                        'scipy.integrate.quadrature',
                        'scipy.integrate.odepack',
                        'scipy.integrate._odepack',
                        'scipy.integrate.quadpack',
                        'scipy.integrate._quadpack',
                        'scipy.integrate._ode',
                        'scipy.integrate.vode',
                        'scipy.integrate._dop', 'scipy._lib', 'scipy._build_utils','scipy.__config__',
                        'scipy.integrate.lsoda', 'scipy.cluster', 'scipy.constants','scipy.fftpack','scipy.interpolate','scipy.io','scipy.linalg','scipy.misc','scipy.ndimage','scipy.odr','scipy.optimize','scipy.setup','scipy.sparse','scipy.spatial','scipy.special','scipy.stats','scipy.version'],
         hookspath=[],
         runtime_hooks=[],
         excludes=[],
         win_no_prefer_redirects=False,
         win_private_assemblies=False,
         cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
         cipher=block_cipher)
exe = EXE(pyz,
      a.scripts,
      a.binaries,
      a.zipfiles,
      a.datas,
      name='constantG_constantHz',
      debug=False,
      strip=False,
      upx=False,
      runtime_tmpdir=None,
      console=True )
Erik
  • 1,196
  • 2
  • 9
  • 18
  • 2
    I agree with the sentiment "if it ain't broke, don't fix it", but instead of manually adding each dll, you can add the folder where they are located as another path in the pathex variable. That tells pyinstaller to look there for other libraries – The4thIceman Nov 04 '17 at 14:24