'Pyinstaller failed to execute script: FileNotFoundError: No file or directory: 'C:\\Users\\etc'
I have a python file I am converting to exe
via Pyinstaller
. The coversion runs fine with no error, however when I run the exe file I get error in line 13 of the python file (line is import librosa). Then I get a bunch of files and then a
FileNotFoundError: No file or directory: 'C:\\Users\\johnny\\Appdata\\Local\\Temp\\_MEI70722\\librosa\\util\\example_data\\registry.txt'.
Also the python file itself runs fine. Any help would be appreciated
Solution 1:[1]
PyInstaller tries to find all the dependencies, however this file is not imported but loaded so it misses it. You can simply force it to add it:
--add-data [path to your python]/Lib/site-packages/librosa/util/example_data;librosa/util/example_data
With The full command be like :
pyinstaller --onefile [YourScript].py --add-data [path to your python]/Lib/site-packages/librosa/util/example_data/registry.txt;librosa/util/example_data
Solution 2:[2]
You'll need to specify the data files as PyInstaller hooks.
- Create a folder "extra-hooks", and in it a file "hook-librosa.py"
- paste these 2 lines in "extra-hooks/hook-librosa.py":
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('librosa')
- Then tell PyInstaller where to locate this file with adding 1 of the following to your PyInstaller command:
--additional-hooks=extra-hooks
--additional-hooks-dir "[PATH_TO_YOUR_PROJECT]/axtra-hooks"
The 2nd one worked for me, and I was using auto-py-to-exe
, built on PyInstaller
.
Solution 3:[3]
I guess the file doesn't exist. Open a file manager
and copy the directory.
Solution 4:[4]
In the PyInstaller
, you should type in the python file's name and then --onefile
. It makes an .EXE
file (if you are on windows) with all the imported files within. You can learn more here: https://pyinstaller.readthedocs.io/en/stable/usage.html
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Brian |
Solution 2 | belferink1996 |
Solution 3 | Wrench56 |
Solution 4 | Wrench56 |