问题
I have coded a python script involving excel sheet manipulation using openpyxl
. Script is running fine using python interpreter. Once I have made single windows executable using pyinstaller
and running the program, its throwing error:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\....\\AppData\\Local\\Temp\\_MEI31842\\.constants.json'
Any suggestion?
回答1:
You might need to tell PyInstaller to include this file:
Put a file hook-openpyxl.py
in the directory from where you run pyinstaller:
# hook-openpyxl.py
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('openpyxl')
Then run pyinstaller as:
pyinstaller --additional-hooks-dir=. yourscriptname.py
回答2:
I am using Openpyxl version 2.5.12 Python 3.7 and Pyinstaller version 3.4
I am able to compile the exe without error. The command I am using is as follows:
pyinstaller --onefile --icon ABC.ico "..\\src\\src_file.py"
来源:https://stackoverflow.com/questions/36076319/filenotfounderror-errno-2-no-such-file-or-directory-constants-json