pythonpyinstallerpywt

Pyinstaller ImportError on pywt `_ctw` module


Pywt is not importing _cwt module correctly when the program is compiled with Pyinstaller. I verified that _cwt.py is present in my pywt root (in site-packages on the path) and _cwt.pyd is in the pywt\_extensions dir. I can successfully import pywt from Python. Below is a minimum (non) working example to illustrate the ImportError traceback.

Program pywt_test.py

# -*- coding: utf-8 -*-
try:
    import sys, traceback
    import pywt
    print pywt.__version__
except ImportError:
    type_, value_, traceback_ = sys.exc_info()
    e_msg = traceback.format_exception(type_, value_, traceback_)
    with open('pywt_error_log.txt','w') as f:
        f.write(''.join(e_msg))

Pyinstaller spec file pywt_test.spec

 # -*- mode: python -*-

 block_cipher = None


 a = Analysis(['pywt_test.py'],
         pathex=['C:\\Users\\user', 'C:\\Users\\user'],
         binaries=[],
         datas=[],
         hiddenimports=[],
         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='pywt_test',
      debug=False,
      strip=False,
      upx=False,
      console=True)

Pyinstall compile command: pyinstaller pywt_test.spec.

Command ran: pywt_test.exe

Contents of pywt_error_log.txt:

Traceback (most recent call last):
  File "pywt_test.py", line 10, in <module>
  File "c:\users\user\appdata\local\temp\pip-build-3zvqo7\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
  File "site-packages\pywt\__init__.py", line 16, in <module>
  File "c:\users\user\appdata\local\temp\pip-build-3zvqo7\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line 546, in load_module
  File "pywt\_extensions\_pywt.pyx", line 1, in init pywt._extensions._pywt (pywt\_extensions\_pywt.c:32588)
 ImportError: No module named _cwt

I tried adding _cwt to the pathex, hiddenimports, etc. None change the error.

How can I get _cwt, and the entire pywt package, to load with Pyinstaller?

Versions, for reference:


Solution

  • Just add it to the hidden imports:

     ...
     hiddenimports=['pywt._extensions._cwt'],
     ...