python-3.xtableau-apipyinstallerhyper-api

pysintaller exe file does not run, throws could not find Hyper API binary directory error


I've created a python script that creates a Tableau (.hyper) extract file using the Tableau Hyper Api. Largely based on the sample scripts provided by Tableau.

I'm trying to package this using pyinstaller. Pyinstaller creates the exe "successfully" but when I try run the exe I get this error:

Traceback (most recent call last):
  File "create_datasource.py", line 3, in <module>
    import tableauhyperapi
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "C:\Users\user\AppData\Roaming\Python\Python38\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "tableauhyperapi\__init__.py", line 126, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "C:\Users\user\AppData\Roaming\Python\Python38\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "tableauhyperapi\catalog.py", line 15, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "C:\Users\user\AppData\Roaming\Python\Python38\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "tableauhyperapi\connection.py", line 20, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "C:\Users\user\AppData\Roaming\Python\Python38\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "tableauhyperapi\result.py", line 18, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "C:\Users\user\AppData\Roaming\Python\Python38\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "tableauhyperapi\date.py", line 14, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "C:\Users\user\AppData\Roaming\Python\Python38\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "tableauhyperapi\impl\hapi.py", line 14, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "C:\Users\user\AppData\Roaming\Python\Python38\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "tableauhyperapi\impl\dll.py", line 28, in <module>
  File "tableauhyperapi\impl\util.py", line 65, in find_hyper_api_library
RuntimeError: tableauhyperapi.dll library not found. Could not find the Hyper API binary directory, tried C:\Users\user\AppData\Local\Temp\_MEI450082\tableauhyperapi\bin.
[43160] Failed to execute script create_datasource

I've tried adding the tableauhyperapi.dll as a binary file to the pyinstaller command, but it still throws the above error.

Could anyone assist with where I'm going wrong?


Solution

  • You need to add the dll specifically so it is extracted to the relative folder named in the second-last line of the error message - the relative folder after _MEI450082.

    If you can’t figure out how to do this read the documentation pyinstaller.readthedocs.io/en/stable/

    Basically you need to add something like this to your pyinstaller command:

    —add-binary “c:\full\path\to\tableauhyperapi.dll;tableauhyperapi/bin”
    

    There might be other files to add once you’ve got that one working.