【问题标题】:Pyinstaller does not include libsndfilePyinstaller 不包含 libsndfile
【发布时间】:2018-11-23 02:43:18
【问题描述】:

我用这段代码和 pyinstaller 创建了一个可执行文件:

import soundfile

print("Hello!")
input("Ok")

但它运行不正确。我收到以下错误:

Traceback (most recent call last):
  File "lib\site-packages\soundfile.py", line 142, in <module>
OSError: sndfile library not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "prueba.py", line 1, in <module>
    import soundfile
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "C:\Users\DianaCarolina\Google Drive\Humboldt\DTF_GUI\venv1\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "lib\site-packages\soundfile.py", line 163, in <module>
OSError: cannot load library 'C:\Users\DianaCarolina\Google Drive\Humboldt\DTF_GUI\dist\prueba\_soundfile_data\libsndfile32bit.dll': error 0x7e
[9780] Failed to execute script prueba

由于我使用了标准的 pyinstaller 命令pyinstaller prueba.py,我能够通过复制 dist 文件夹中的原始 _soundfile_data 文件夹来使可执行文件工作。但是,我想使用 --onefile 选项使我的程序更易于分发。如何让 pyinstaller 按预期工作?

【问题讨论】:

    标签: python-3.x pyinstaller libsndfile


    【解决方案1】:

    像这样添加为外部钩子

    pyinstaller <your parameters> --hidden-import='package.module'
    

    【讨论】:

    • 什么是 package.module?我已经尝试将路径放置到 _soundfile_data 并且它不起作用,它需要复制 dist 文件夹中的所有文件夹才能工作,但不能那样做。顺便说一句,该文件夹已经在 site-packages 文件夹中
    • e.g : from PIL import ImageTk 这里 PIL 是包,imageTk 是模块,所以像这样的钩子 --hidden-import='PIL.ImageTk'
    【解决方案2】:

    在这种情况下,您可以使用--add-binary 选项。例如:

    --add-binary /path/to/_soundfile_data/libsndfile.dylib:_soundfile_data

    在我的情况下,我发现(活动)conda 环境 pysndfile 已安装并从中获取 libsndfile:--add-binary $(dirname $(which python))/../lib/python3.7/site-packages/_soundfile_data/libsndfile.dylib:_soundfile_data

    【讨论】:

      猜你喜欢
      • 2020-11-09
      • 1970-01-01
      • 2020-04-02
      • 1970-01-01
      • 2023-01-18
      • 2020-03-23
      • 1970-01-01
      • 2020-10-29
      • 1970-01-01
      相关资源
      最近更新 更多