pysintaller exe 文件没有 运行,抛出找不到 Hyper API 二进制目录错误
pysintaller exe file does not run, throws could not find Hyper API binary directory error
我创建了一个 python 脚本,该脚本使用 Tableau Hyper Api 创建 Tableau (.hyper) 提取文件。主要基于 Tableau 提供的示例脚本。
我正在尝试使用 pyinstaller 对其进行打包。 Pyinstaller“成功”创建了 exe,但是当我尝试 运行 exe 时,出现此错误:
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
我已经尝试将 tableauhyperapi.dll 作为二进制文件添加到 pyinstaller 命令中,但它仍然会抛出上述错误。
任何人都可以帮助我哪里出错了吗?
您需要专门添加dll,以便将其提取到错误消息second-last行中指定的相对文件夹-_MEI450082之后的相对文件夹。
如果您不知道如何执行此操作,请阅读文档 pyinstaller.readthedocs。io/en/stable/
基本上你需要在你的 pyinstaller 命令中添加这样的东西:
—add-binary “c:\full\path\to\tableauhyperapi.dll;tableauhyperapi/bin”
一旦您的文件正常运行,可能还需要添加其他文件。
添加到 barny 的答案并特定于 tableau hyper API,您将 运行 变成 Could not auto-detect Hyper binary: Hyper binary is not in the expected directory AppData\Local\Temp\_MEI176802\tableauhyperapi\bin\hyper
使用 --add-data 来解决这个问题。命令:
pyinstaller --onefile --name ExecName.exe --paths 'c:\full\path\to\site-packages' --add-binary 'c:\full\path\to\site-packages\tableauhyperapi\bin\tableauhyperapi.dll;tableauhyperapi/bin' --add-data 'c:\full\path\to\site-packages\tableauhyperapi\bin\hyper;tableauhyperapi/bin/hyper' Script.py
我创建了一个 python 脚本,该脚本使用 Tableau Hyper Api 创建 Tableau (.hyper) 提取文件。主要基于 Tableau 提供的示例脚本。
我正在尝试使用 pyinstaller 对其进行打包。 Pyinstaller“成功”创建了 exe,但是当我尝试 运行 exe 时,出现此错误:
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
我已经尝试将 tableauhyperapi.dll 作为二进制文件添加到 pyinstaller 命令中,但它仍然会抛出上述错误。
任何人都可以帮助我哪里出错了吗?
您需要专门添加dll,以便将其提取到错误消息second-last行中指定的相对文件夹-_MEI450082之后的相对文件夹。
如果您不知道如何执行此操作,请阅读文档 pyinstaller.readthedocs。io/en/stable/
基本上你需要在你的 pyinstaller 命令中添加这样的东西:
—add-binary “c:\full\path\to\tableauhyperapi.dll;tableauhyperapi/bin”
一旦您的文件正常运行,可能还需要添加其他文件。
添加到 barny 的答案并特定于 tableau hyper API,您将 运行 变成 Could not auto-detect Hyper binary: Hyper binary is not in the expected directory AppData\Local\Temp\_MEI176802\tableauhyperapi\bin\hyper
使用 --add-data 来解决这个问题。命令:
pyinstaller --onefile --name ExecName.exe --paths 'c:\full\path\to\site-packages' --add-binary 'c:\full\path\to\site-packages\tableauhyperapi\bin\tableauhyperapi.dll;tableauhyperapi/bin' --add-data 'c:\full\path\to\site-packages\tableauhyperapi\bin\hyper;tableauhyperapi/bin/hyper' Script.py