1

I created an executable with this code and pyinstaller:

import soundfile

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

But it doesn't run correctly. I get the following error:

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

Since I used the standard pyinstaller command pyinstaller prueba.py I was able to make the executable work by copying the original _soundfile_data folder in the dist folder. However, I would like to use the --onefile option to make my program easier to distribute. How can I make pyinstaller work as it is supposed to?

dduque
  • 338
  • 4
  • 16

2 Answers2

0

add as external hook like this

pyinstaller <your parameters> --hidden-import='package.module'
MohitGhodasara
  • 2,342
  • 1
  • 22
  • 29
  • What is package.module? I already tried that putting the path to the _soundfile_data and it didn't work, it needs to copy all the folder in the dist folder for it to work and it can't be done like that. That folder is already in the site-packages folder by the way – dduque Nov 30 '18 at 15:52
  • e.g : from PIL import ImageTk here PIL is package and imageTk is module so hook like this --hidden-import='PIL.ImageTk' – MohitGhodasara Dec 03 '18 at 05:48
0

You can use the --add-binary option in cases like this. For example:

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

In my case I find the (active) conda environment pysndfile is installed into and get libsndfile out of that: --add-binary $(dirname $(which python))/../lib/python3.7/site-packages/_soundfile_data/libsndfile.dylib:_soundfile_data