我用下面的代码和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命令dist,因此我能够通过复制dist文件夹中的原始_soundfile_data文件夹来使可执行文件工作。但是,我想使用--onefile选项来使我的程序更容易分发。我怎样才能让pyinstaller像它应该的那样工作?
发布于 2018-11-30 19:53:31
添加为外部挂钩,如下所示
pyinstaller <your parameters> --hidden-import='package.module'发布于 2019-03-18 03:50:29
在这种情况下,您可以使用--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
https://stackoverflow.com/questions/53440062
复制相似问题